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

后端 未结 2 1525
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 21:39

I just noticed that MVC 5 is using a different class for input fields when using EditorFor. I think its from a lower version of bootstrap, so the current class doesn\'t really a

2条回答
  •  感情败类
    2021-02-18 22:09

    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" })
    

提交回复
热议问题