0
我想在mvc中動態顯示視圖中的項目。 以下是在視圖中顯示的記錄如何在mvc4中動態顯示視圖中的項目
@using MvcWcf.ServiceReference1
@model IEnumerable<WcfService.MyAddress>
<table>
<tr>
<td>@Html.DisplayNameFor(model => model.Address1)</td>
<td>@Html.DisplayNameFor(model => model.City)</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Address1)</td>
<td>@Html.DisplayFor(modelItem => item.City)</td>
</tr>
}
</table>
我的要求如何動態 顯示次項目和記錄例如<td>@Html.DisplayNameFor(model => model.Address1)</td><td>@Html.DisplayNameFor(model => model.City)</td>
這裏我寫address1
和City
,因爲我知道這個領域的代碼。 如果我不知道字段如何顯示。 還顯示記錄
你是什麼意思,你不知道字段?該模型是'MyAddress'類型,因此知道它的屬性。 – 2014-11-04 06:36:53
請您詳細說明一下嗎?你是什麼意思動態? – 2014-11-04 07:17:41
我認爲他希望擁有從1到N個元素的視圖的通用模型。 – theLaw 2014-11-04 07:37:23