我尝试为 EditorFor 添加 html 属性
@Html.EditorFor(model => model.UserName, new { style = "width: 100px" })
但不管怎样
<input id="UserName" class="text-box single-line" type="text" value="" name="UserName">
最佳答案
EditorFor 将覆盖这些属性。参见 Html attributes for EditorFor() in ASP.NET MVC解决方法。
如果您需要更改的只是宽度的显示,并且您不依赖任何编辑器模板,那么最简单的解决方法是改用 TextBoxFor
@Html.TextBoxFor(model => model.UserName, new { style = "width: 100px" })
关于c# - mvc 3 Html.EditorFor 添加 html 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6550972/