c# - mvc 3 Html.EditorFor 添加 html 属性不起作用

标签 c# html asp.net-mvc-3 razor editor

我尝试为 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/

相关文章:

c# - .NET framework 中位标志的实际使用

html - 如何指定用户必须插入输入字段的确切位数?

Javascript垂直居中事件元素

asp.net-mvc-3 - MVC3 部分 View - Ajax.BeginForm 还是 Ajax.ActionLink 更好?

asp.net-mvc-3 - 在 MVC 3 上启用蓝屏死机

c# - 卡在 Xamarin AAPT 错误上

c# - Irony 语法规范错误

c# - Azure 函数 - 从 DefaultCredentials\Managed Identity 获取 token

jquery - 在 jquery datepicker 中更改周末日期的字体颜色

c# - ViewBag 作为 session 模型的持有者