asp.net-mvc 只读 ASP.net MVC 视图中的文本框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2164025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:06:15 来源:igfitidea点击:
read only Textbox in ASP.net MVC View
提问by Rita
How to set the readonly attribute to HTML Textbox helper class.
如何将 readonly 属性设置为 HTML Textbox helper 类。
<%= Html.TextBox("Email", "[email protected]", new { @class = "required email" } )%>
Appreciate your response Thanks
感谢您的回复 谢谢
回答by Alex LE
<%= Html.TextBox("Email", "[email protected]", new { @class = "required email", @readonly="readonly" }) %>
回答by Mattias Jakobsson
<%= Html.TextBox("Email", "[email protected]", new { @class = "required email", @readonly = "readonly" } )%>
回答by Mohammad Dayyan
For better performance, use the following :
为了获得更好的性能,请使用以下内容:
ASPX:
ASPX:
<%= Html.TextBox("Email", ew Dictionary<string, object> { {"class","required email"}, {"readonly","readonly"} } %>
Razor:
剃刀:
@Html.TextBoxFor(model => model.Email, new Dictionary<string, object> { { "class", "required email" }, {"readonly","readonly"} })
回答by Danilow
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @readonly = "readonly" } })
works for me
对我来说有效
回答by Danilow
<%= Html.TextBox("Email", "[email protected]", new { @class = "required email", readonly="true" } )%>
回答by Hacker
<%= Html.TextBox("Email", "[email protected]", new { @class = "required email", @readonly="readonly" } )%>
@ symbol bypasses the reserved word.
@ 符号绕过保留字。

