Applying CSS Class To Html.TextBoxFor

Jun 22, 2013


Working with the Asp .Net MVC application we use a lot of HtmlHelper(s). While using this helpers, we might want to apply some styling attribute to our components. In this short blog post we will see how we can apply CSS class while using Html.TextBoxFor HtmlHelper.

To look at the example, we will continue with our WhiteLabel solution we built in one of our previous blog post. Again, we have a model class let's say Asset and we want to apply a CSS class when we use Html.TextBoxFor HtmlHelper.

CSS class

While using the TextBoxFor , here is how we can apply this class.

CSS class

This is very similar to how we have applied ReadOnly attribute to our Input field is this blog post.

Rendered HTMl