部分视图不传递视图模型时传递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