Addind css classes to razor elements

后端 未结 3 783
无人共我
无人共我 2021-01-12 03:03

In razor if I had something like:

@Html.EditorFor(model => model.name) or even: @Html.CheckBoxFor(m => m.RememberMe)

How woul

3条回答
  •  礼貌的吻别
    2021-01-12 03:37

    It's easy for CheckboxFor, you can do it like this:

    @Html.CheckBoxFor(m => m.RememberMe, new { @class="your_class", @id="the_id" })
    

    It's a bit trickier with EditorFor as it is NOT supported out of the box. What I mean is you can create a template for each type and then do a TextBoxFor adding html attributes (same syntax as with CheckBoxFor). You may have to do it for each type you want supported.

提交回复
热议问题