MVC5 and Bootstrap3: Html.EditorFor wrong class? How to change?

无人久伴 提交于 2019-12-04 22:43:45

EditorFor doesn't accept HTML attributes as a parameter. The parameter you are using is actually additionalViewData

Use TextBoxFor instead

@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })

Edit

As of MVC 5.1, HTML attributes can be passed to the EditorTemplate using this syntax

@Html.EditorFor(m => m.UserName, new { htmlAttributes = new { @class = "form-control" } })
user5759686

If you are using the MVC 5 or prior version use @Html.TextBoxFor instead of @Html.EditorFor as given in the following code:

@Html.TextBoxFor(model => model.CivilStatus,new { @class = "form-control" }

and if you also have to bind it knockout.js modelview attribute then:

@Html.TextBoxFor(model => model.CivilStatus, new { data_bind="value: author.civilStatus", @class = "form-control" })

I have used this with MVC4, it's working for me:

@Html.TextBoxFor(model => model.FirstName, new { data_bind="value: author.firstName", @class = "form-control" })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!