title: How to inject a css class into an MvcHtmlString?
body: <p>Is it possible to inject a css class into an HTML element that has been encapsulated within an <code>MvcHtmlString</code>? </p>
  
  <p>I've been tasked, as part of the framework I'm building, with creating my own versions of the MVC extension methods for form elements (<code>TextBox</code>, <code>TextBoxFor&lt;&gt;</code>, etc), with the following caveats:</p>
  
  <ul>
  <li>that they must create the correct HTML markup, including CSS classes, to match the styles that have already been designed for the site. In the majority of cases, this simply means the addition of a specific class.</li>
  <li>that they must be as true to the MVC extension methods as possible so that developers feel comfortable using them</li>
  </ul>
  
  <p>Most, if not all, of the MVC extension methods return an <code>MvcHtmlString</code> so the simplest way to mimic the functionality is to call those methods directly from my methods. I have my own Html Helper, <code>OuHelper</code>, that my framework is using, so developers wishing to create, for example, a <code>TextBox</code>, would call something along the lines of:</p>
  
  <blockquote>
    <p>`@Ou.TextBoxFor(m => m.Username)</p>
  </blockquote>
  
  <p>And I would like the resulting Html to render like so:</p>
  
  <blockquote>
    <p><code>&lt;input type="text" name="Username" id="Username" class="int-text" /&gt;</code></p>
  </blockquote>
  
  <p>If I create my own versions of the overloads as they are in the MVC framework, I will be able to control adding the extra CSS classes where needed but that seems like overkill for such a small change of HTML output from those methods. I would need to provide equivalent implementations of all of the overloads (for <code>TextBox</code> alone there are about 12 when you count the generic and non-generic versions). What I would like to do is <code>TagBuilder</code> in reverse (start with the output and create an object from it that will enable things like <code>MergeAttributes</code> to be available) but I don't think that's possible.</p>
  
  <p>To be clear: the framework code that I am writing needs to add the css classes itself, but it should be possible for developers using the extension methods that I create to add their own custom css classes as well. These would be added/appended as per the standard MVC framework form extension methods' functionality</p>