[英]MVC Partial View not rendering
通過ViewModel時不呈現局部視圖。沒有ViewModel的情況下呈現。 我的意思是,如果我保留@ Html.Partial(“ PartialClientIndex”),則呈現它,並且當我傳遞ViewModel時,它將直接轉到Dispose,而不呈現局部視圖。 我在這里想念某物..請您幫忙。
主視圖:
<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>
看來,要作為模型傳遞到部分視圖的變量vmclient
的類型為VMClient
。 盡管您的部分視圖需要IEnumerable<VMClient>
類型。
基本上,您必須將部分視圖中的模型類型更改為以下內容
@model HostingManager.Models.VMClient
並調整分配y
變量的方式
var y = Model.IEClients;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.