在ASP.net MVC视图中只读文本框

时间:2010-01-29 18:03:16

标签: asp.net-mvc

如何将readonly属性设置为HTML Textbox助手类。

<%= Html.TextBox("Email", "abc@abc.com", new { @class = "required email" } )%>

感谢您的回复 感谢

6 个答案:

答案 0 :(得分:65)

<%= Html.TextBox("Email", "abc@abc.com", new { @class = "required email", @readonly="readonly" }) %>

答案 1 :(得分:6)

<%= Html.TextBox("Email", "abc@abc.com", new { @class = "required email", @readonly = "readonly" } )%>

答案 2 :(得分:3)

为了获得更好的性能,请使用以下命令:

ASPX:

<%= Html.TextBox("Email", ew Dictionary<string, object> { {"class","required email"}, {"readonly","readonly"} }  %>

剃刀:

@Html.TextBoxFor(model => model.Email, new Dictionary<string, object> { { "class", "required email" }, {"readonly","readonly"} })

答案 3 :(得分:2)

<%= Html.TextBox("Email", "abc@abc.com", new { @class = "required email", readonly="true" } )%>

答案 4 :(得分:2)

<%= Html.TextBox("Email", "abc@abc.com", new { @class = "required email", @readonly="readonly" } )%>

@符号绕过保留字。

答案 5 :(得分:2)

NA

适合我