Set the class attribute to Html.EditorFor in ASP.NET MVC Razor View

后端 未结 5 923
时光说笑
时光说笑 2020-12-30 20:03

As you know we can set attributes to actionLink or textBox in razor views but how can we set attributes to @Html.EditorFor, I know the EditorFor is a dynamic el

5条回答
  •  醉话见心
    2020-12-30 20:34

    I believe that the original poster was correct

    • each EditorFor()

      creates a main HTML element (though there may be others present), so it would be very helpful to be able to pass an object containing HTML attributes to apply to that main HTML element.

    • I want to apply the HTML 5 'autofocus' attribute to one field on every form,

    • but I DO NOT want to have to write custom code.

    • I hate the fact that I'm currently reduced to using, e.g., @Html.TextBoxFor() for that one field just so that I can apply specific attributes to the input element.

    • The EditorFor() method does have a parameter they call additionalViewData, but I have no idea what you can do with that and searching on MSDN has not been of any help to me.

提交回复
热议问题