3 回答

TA貢獻1876條經驗 獲得超5個贊
更新您的視圖代碼如下,
@model List<QBKartMVC.Models.Products>
@for (var i = 0; i < Model.Count; i++)
{
<tr>
<td><input type="checkbox"></td>
<td>@Html.DisplayFor(x => x[i].ProductCode)</td>
<td>@Html.DisplayFor(x => x[i].ProductName)</td>
<td>@Html.DisplayFor(x => x[i].ProductDes)</td>
<td>@Html.DisplayFor(x => x[i].ActiveFlag)</td>
<td>@Html.DisplayFor(x => x[i].Price)</td>
</tr>
}

TA貢獻1860條經驗 獲得超9個贊
@model List<QBKartMVC.Models.Products>
@foreach (var item in Model)
{
<tr>
<td><input type="checkbox"></td>
<td>item.ProductCode</td>
<td>item.ProductName</td>
<td>item.ProductDes</td>
<td>item.ActiveFlag</td>
<td>item.Price</td>
</tr>
}

TA貢獻1839條經驗 獲得超15個贊
你必須創建 IEnumerable List ,像這樣
@model IEnumerable<QBKartMVC.Models.Products>
@foreach (var item in Model)
{
<tr>
<td><input type="checkbox"></td>
<td>@Html.DisplayFor(x => x.ProductCode)</td>
<td>@Html.DisplayFor(x => x.ProductName)</td>
<td>@Html.DisplayFor(x => x.ProductDes)</td>
<td>@Html.DisplayFor(x => x.ActiveFlag)</td>
<td>@Html.DisplayFor(x => x.Price)</td>
</tr>
}
- 3 回答
- 0 關注
- 214 瀏覽
添加回答
舉報