Asp.net mvc 4 在html输入文本中使用参数调用方法+;剃刀MVC4
我在razor视图(list.cshtml)中将属性值分配给html输入测试框,如下所示Asp.net mvc 4 在html输入文本中使用参数调用方法+;剃刀MVC4,asp.net-mvc-4,razor-2,Asp.net Mvc 4,Razor 2,我在razor视图(list.cshtml)中将属性值分配给html输入测试框,如下所示 string cap=item.GetValForProp(“标题”); 输入type=“text”name=“Caption”class=“txt”value=“@cap” 这个很好用 但是,如果我想写以下内容: input type="text" name="Caption" class="txt" value="@item.GetValForProp<string>("Caption")
string cap=item.GetValForProp(“标题”);
输入type=“text”name=“Caption”class=“txt”value=“@cap”
这个很好用
但是,如果我想写以下内容:
input type="text" name="Caption" class="txt" value="@item.GetValForProp<string>("Caption")"
input type=“text”name=“Caption”class=“txt”value=“@item.GetValForProp(“Caption”)”
未识别“Caption”参数时出现编译错误。若我给出单引号,那个么它并没有将其作为参数,而是给出了无效参数的例外
我怎样才能纠正这个问题
代码块:
@foreach (var item in Model) {
cap = item.GetValForProp<string>("Caption");
nameinuse = item.GetValForProp<string>("NameInUse");
desc = item.GetValForProp<string>("Description");
<tr>
<td class="txt">
<input type="text" name="Caption" class="txt" value="@cap"/>
<input type="text" name="Caption" class="txt" value="@nameinuse"/>
<input type="text" name="Caption" class="txt" value="@desc"/>
</td>
</tr>
}
@foreach(模型中的变量项){
cap=项目。GetValForProp(“标题”);
nameinuse=item.GetValForProp(“nameinuse”);
desc=项目。GetValForProp(“说明”);
}
我通过使用文本框解决了这个问题,如下所示
@Html.TextBox("Caption", item.GetValForProp<string>("Caption"), new { @class = "txt" })
@Html.TextBox(“标题”,item.GetValForProp(“标题”),新{@class=“txt”})
您使用的是IENumerable
模型吗?是的,我的模型是-@model IENumerable
@Html.TextBox("Caption", item.GetValForProp<string>("Caption"), new { @class = "txt" })