Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net MVC文本框只读不工作_.net_Asp.net Mvc - Fatal编程技术网

.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