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

后端 未结 5 937
时光说笑
时光说笑 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:54

    Add custom attributes as

    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @data_minlength = "3", @class = "form-control input-md", @placeholder = "Name", @required = "required", @id= "txtName"} })
    

    Replace data- to @data_

    It will generate correct html with data-

提交回复
热议问题