.net MVC文本框只读不工作
这是我的密码:.net MVC文本框只读不工作,.net,asp.net-mvc,.net,Asp.net Mvc,这是我的密码: <%= Html.TextBox("txtId", new { @readonly = "readonly" })%> 但它不起作用。为什么?使用: <%= Html.TextBox("txtId", new { @readonly = "true" })%> 编辑:最好将TextBoxFor与键入的模型一起使用: <%= Html.TextBoxFor(model => model.Id, new { @readonly = "t
<%= Html.TextBox("txtId", new { @readonly = "readonly" })%>
但它不起作用。为什么?使用:
<%= Html.TextBox("txtId", new { @readonly = "true" })%>
编辑:最好将TextBoxFor与键入的模型一起使用:
<%= Html.TextBoxFor(model => model.Id, new { @readonly = "true" })%>
model.Id,新的{@readonly=“true”})%>
使用:
编辑:最好将TextBoxFor与键入的模型一起使用:
<%= Html.TextBoxFor(model => model.Id, new { @readonly = "true" })%>
model.Id,新的{@readonly=“true”})%>
属性应该是第三个参数
TextBox('ID', 'value', 'attributes'
属性应该是第三个参数
TextBox('ID', 'value', 'attributes'
试一试
(第二个参数是值,第三个代表HTML属性)
代码中的问题是新{@readonly=“readonly”}
对象被解释为要在文本框中显示的值
(第二个参数是值,第三个代表HTML属性)
代码中的问题是
新的{@readonly=“readonly”}
对象被解释为要在文本框中显示的值缺少第二个参数。您希望将模型的哪个属性绑定到此文本框。这应该是第二个参数
<%= Html.TextBox("ID", Model.Attr, new { @readonly="readonly" })%>
当然,如果不想绑定到模型,请使用null作为第二个属性:
<%= Html.TextBox("ID", null, new { @readonly="readonly" })%>
缺少第二个参数。您希望将模型的哪个属性绑定到此文本框。这应该是第二个参数
<%= Html.TextBox("ID", Model.Attr, new { @readonly="readonly" })%>
当然,如果不想绑定到模型,请使用null作为第二个属性:
<%= Html.TextBox("ID", null, new { @readonly="readonly" })%>
这是正确的代码。第二个参数指定文本框的值。
这是正确的代码。第二个参数指定文本框的值。使用下面的代码
<%= Html.TextBox("txtId", string.Empty ,new { @readonly = "readonly" })%>
使用下面的代码
<%= Html.TextBox("txtId", string.Empty ,new { @readonly = "readonly" })%>
在我的例子中,我意识到显示值的数据类型必须是字符串。 因此,我将model.SOME_DATE从DateTime转换为string,代码运行良好
@Html.EditorFor(model => model.SOME_DATE, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
在我的例子中,我意识到显示值的数据类型必须是字符串。 因此,我将model.SOME_DATE从DateTime转换为string,代码运行良好
@Html.EditorFor(model => model.SOME_DATE, new { htmlAttributes = new { @class = "form-control", @readonly = true } })
呈现的html看起来像什么?@asawyer呈现的html看起来像什么?@asawyer