ASP.NET MVC 3 Razor - Adding class to EditorFor

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

    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:

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

提交回复
热议问题