Partial view is not rendering while passing ViewModel.. Its rendering without ViewModel. I mean if I keep @Html.Partial("PartialClientIndex") then its rendering and when I pass ViewModel it directly going to Dispose without rendering partial view. I'm missing something here.. could you please help in this.
Main View:
<div id="PartialClient">
@Html.Partial("PartialClientIndex", viewModelList)
</div>
Action:
[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);
}
Partial View:
@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>
It seems that the variable vmclient
that you are passing as model into your partial view is of type VMClient
. Though your partial view is expecting the IEnumerable<VMClient>
type.
You basically have to change the model type in your partial view to the following
@model HostingManager.Models.VMClient
and adjust the way you are assigning the y
variable
var y = Model.IEClients;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.