ASP.NET MVC 3 Razor – Adding class to EditorFor

Adding a class to Html.EditorFor doesn’t make sense as inside its template you could have many different tags. So you need to assign the class inside the editor template:

@Html.EditorFor(x => x.Created)

and in the custom template:

<div>
    @Html.TextBoxForModel(x => x.Created, new { @class = "date" })
</div>

Leave a Comment