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

后端 未结 2 1524
爱一瞬间的悲伤
爱一瞬间的悲伤 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 21:49

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

提交回复
热议问题