ASP.NET MVC 3 Razor - Adding class to EditorFor

后端 未结 16 2060
长情又很酷
长情又很酷 2020-11-27 11:09

I\'m trying to add a class to an input.

This is not working:

@Html.EditorFor(x => x.Created, new { @class = \"date\" })
16条回答
  •  清酒与你
    2020-11-27 11:46

    As of ASP.NET MVC 5.1, adding a class to an EditorFor is possible (the original question specified ASP.NET MVC 3, and the accepted answer is still the best with that considered).

    @Html.EditorFor(x=> x.MyProperty,
        new { htmlAttributes = new { @class = "MyCssClass" } })
    

    See: What's New in ASP.NET MVC 5.1, Bootstrap support for editor templates

提交回复
热议问题