ASP.NET MVC 3 Razor - Adding class to EditorFor

后端 未结 16 2085
长情又很酷
长情又很酷 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:32

    It is possible to provide a class or other information through AdditionalViewData - I use this where I'm allowing a user to create a form based on database fields (propertyName, editorType, and editorClass).

    Based on your initial example:

    @Html.EditorFor(x => x.Created, new { cssClass = "date" })
    

    and in the custom template:

    @Html.TextBoxFor(x => x.Created, new { @class = ViewData["cssClass"] })

提交回复
热议问题