我視圖模型和模型如下綁定模型到文本框在Razor視圖
public class MyViewModel
{
public List<MyModel> MyItems { get; set; }
/* There are many other properties*/
}
public class MyModel
{
public string MyType { get; set; }
public decimal value1 { get; set; }
public decimal value2 { get; set; }
}
我綁定,如下Razor視圖。對於第1列,我只能顯示字符串。對於第2列和第3列,我需要使用模型中的數據顯示文本框。
<table >
<thead>
<tr>
<th>My Column1</th>
<th>My Column2</th>
<th>My Column3</th>
</tr>
</thead>
<tbody>
@foreach (var myItem in Model.MyItems)
{
<tr>
<td>
@myItem.MyType
</td>
<td>@Html.TextBoxFor(???)</td>
<td></td>
</tr>
}
</tbody>
</table>
在正常情況下,我看到,我們可以這樣做@ Html.TextBoxFor(M => m.myvalue1)。但是如何在上述情況下做到這一點。請建議。
以上的作品 - Html.TextBoxFor(M => m.MyItems [1])。 value1 在此處找到更多詳細信息 - http://stackoverflow.com/questions/8894442/mvc-razor-view-nested-foreachs-model – San