MVC 3 Html.EditorFor添加HTML属性不起作用 [英] mvc 3 Html.EditorFor add html attribute not work

查看:162
本文介绍了MVC 3 Html.EditorFor添加HTML属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加HTML属性,EditorFor

  @ Html.EditorFor(型号=> model.UserName,新{风格=WIDTH:100px的})

但无论如何,我得到

 <输入ID =用户名级=文本框单行TYPE =文本值=NAME =用户名>


解决方案

EditorFor是要覆盖这些属性。请参见的HTML ASP.NET MVC 属性EditorFor()对于解决办法。

如果你需要改变的是宽度的显示,和你没有任何编辑模板依托那么最简单的解决办法是使用TextBoxFor而不是

  @ Html.TextBoxFor(型号=> model.UserName,新{风格=WIDTH:100px的})

I try add html attribute for EditorFor

 @Html.EditorFor(model => model.UserName, new { style = "width: 100px" })

But any way I get

<input id="UserName" class="text-box single-line" type="text" value="" name="UserName">

解决方案

EditorFor is going to overwrite those attributes. See Html attributes for EditorFor() in ASP.NET MVC for workarounds.

If all you need to change is the display of the width, and you're not relying on any Editor Templates then the easiest fix is to use TextBoxFor instead

 @Html.TextBoxFor(model => model.UserName, new { style = "width: 100px" })

这篇关于MVC 3 Html.EditorFor添加HTML属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆