gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:43:32 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com