部分視圖不傳遞視圖模型時傳遞ViewModel。其渲染沒有ViewModel。 我的意思是如果我保留@ Html.Partial(「PartialClientIndex」),那麼它的渲染,當我傳遞ViewModel時,它直接進入Dispose而不渲染局部視圖。 我在這裏錯過了一些東西..你能否在此幫忙。MVC部分視圖不呈現
主視圖:
<div id="PartialClient">
@Html.Partial("PartialClientIndex", viewModelList)
</div>
操作:
[HttpPost]
public ActionResult PartialClientIndex(int? SelectedGroupId)
{
int SkipRec = 0;
int NextRec = 25;
VMClient vmclient = new VMClient();
vmclient.IEClients = db.client.Where(cl => cl.Groups.id == SelectedGroupId).OrderBy(c => c.id).Skip(SkipRec).Take(NextRec).ToList();
return PartialView("PartialClientIndex", vmclient);
}
管窺:
@model IEnumerable<HostingManager.Models.VMClient>
<table>
<thead>
<tr>
<th style="width:25px; padding:10px;">
Group
</th>
<th class="tbContent-Name">
Client Name
</th>
<th class="tbContent-Name">
Contact Person
</th>
<th class="tbContent-Name">
Contact Email
</th >
<th></th>
</tr>
</thead>
<tbody>
@if(Model != null)
{
var x = Model.Select(c=>c.IEClients).ToList();
var y = x[0].ToList();
// var y = x[0]["item1"];
foreach (var item in y) {
<tr>
<td class="tbContent-Name">
@Html.DisplayFor(modelItem => item.Groups.name)
</td>
<td class="tbContent-Name">
@Html.DisplayFor(modelItem => item.contactPerson)
</td>
<td class="tbContent-Name">
@Html.DisplayFor(modelItem => item.contactPerson)
</td>
<td class="tbContent-Name">
@Html.DisplayFor(modelItem => item.contactEmail)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.id }, new { onclick = "return confirm('Are you sure you wish to delete this ?');" })
</td>
</tr>
}
}
</tbody>
顯示局部視圖代碼 – 2014-10-11 15:58:38
我有辦法添加部分視圖代碼@Ehsan Sajjad ..你可以請教建議 – Mukarram 2014-10-11 16:10:35
乍一看,你試圖傳遞一個模型到一個'ActionResult',要求一個'int?' – ethorn10 2014-10-11 16:47:52