Asp.net mvc 如何在ASP.NET MVC4中创建只读文本框

Asp.net mvc 如何在ASP.NET MVC4中创建只读文本框,asp.net-mvc,razor,Asp.net Mvc,Razor,我正在使用 <td>@Html.TextBoxFor("code",new { @readonly="readonly" })</td> @Html.TextBoxFor(“code”,新的{@readonly=“readonly”}) 但是有一个错误。正确的语法是什么 错误: Error 1 The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TM

我正在使用

 <td>@Html.TextBoxFor("code",new { @readonly="readonly" })</td>
@Html.TextBoxFor(“code”,新的{@readonly=“readonly”})
但是有一个错误。正确的语法是什么

错误:

Error   1   The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>, System.Collections.Generic.IDictionary<string,object>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.  c:\Users\ATPL\Documents\Visual Studio 2012\Projects\AST_MGMT\AST_MGMT\Views\Department\Add.cshtml   7   18  AST_MGMT
Error 1无法根据用法推断方法“System.Web.Mvc.Html.InputExtensions.TextBoxFor(System.Web.Mvc.HtmlHelper、System.Linq.Expressions.Expression、System.Collections.Generic.IDictionary)”的类型参数。尝试显式指定类型参数。c:\Users\ATPL\Documents\Visual Studio 2012\Projects\AST\u MGMT\AST\u MGMT\Views\Department\Add.cshtml 7 18 AST\u MGMT

假设您的视图中有一个模型,您可以在“模型”表示您的模型的地方使用类似的内容:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })

假设您的视图中有一个模型,您可以使用类似这样的东西,其中“模型”表示您的模型:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })
您应该尝试
@Html.TextBox(“code”,new{@readonly=“readonly”})
,当使用
TextBoxFor
时,您需要使用lambda表达式从视图模型传递属性。

您应该尝试
@Html.TextBox(“code”,new{@readonly=“readonly”})
,使用
TextBoxFor
时,需要使用lambda表达式从视图模型中传递属性。

对于
@Html.TextBoxFor()
使用:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })
@Html.TextBox("code", "default value ", new { @readonly="readonly" })
对于
@Html.TextBox()
使用:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })
@Html.TextBox("code", "default value ", new { @readonly="readonly" })
对于
@Html.TextBoxFor()
使用:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })
@Html.TextBox("code", "default value ", new { @readonly="readonly" })
对于
@Html.TextBox()
使用:

@Html.TextBoxFor(model => model.code, new { @readonly="readonly" })
@Html.TextBox("code", "default value ", new { @readonly="readonly" })

指定类型
TextBoxFor
(我假设存在这样的问题)我相信问题在于字符串文字“code”,而不是
只读的
。这需要一个与您的模型相关的lambda。例如,如果您有一个名为
code
@Html.TextBoxFor(m=>m.code,new{@readonly=“readonly”})
的属性,执行此操作时会出现错误CS1963:表达式树可能不包含动态操作指定类型
TextBoxFor
(我假设存在这样的问题)我相信问题在于字符串文字“code”,而不是
只读的
。这需要一个与您的模型相关的lambda。例如,如果您有一个名为
code
@Html.TextBoxFor(m=>m.code,new{@readonly=“readonly”})
的属性,则执行此操作时会出现错误CS1963:表达式树可能不包含动态操作