ASP.NET MVC adding class attribute to Textbox element

Posted on

Quick tip how to add class attribute to element using HTMLHelper class. I was trying to add required class name to enable validation and of cause found that class is reserved. Solution is simple – use @class

<%= Html.TextBox("LastName", Model.LastName, new { @class = "required" })%>

Tags: , ,