你好我是MVC 4的新手。我遇到了partialView的问题..我goole它并搜索了很多并研究了不同的教程但是找不到任何可以解决我的问题的解决方案。我创建了一个PagedList到在Index.cshtml页面上显示记录。然后我创建了PartialIndex.cshtml页面以在Partial View中显示记录。 这是问题:当我点击任何页码或导航..整个页面刷新并回发...部分视图不起作用。不知道我做错了什么。 我想在PartialIndex.cshtml中的DIV中显示表格
PartialIndex.cshtml:
<div id="targetContainer"> //I want to show this DIV in partial view.
<table>
<tr>
<th>
@Html.ActionLink("ID", "Index", new { sortOrder = ViewBag.customerID, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
</th>
<th>
@Html.DisplayName("First Name")
</th>
<th></th>
<th>
@Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.lName, currentFilter=ViewBag.CurrentFilter })
</th>
<th></th>
<th>
@Html.DisplayName("Contact Num")
</th>
<th>
@Html.DisplayName("Address")
</th>
<th>
@Html.DisplayName("Email")
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.customerId)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.fName)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.lName)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.contactNum)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.address)
</td>
<td>
</td>
<td>
@Html.DisplayFor(modelItem => item.email)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID })
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
</div>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "GET", UpdateTargetId = "targetContainer" }))
Index.cshtml:
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.Partial("PartialIndex")
答案 0 :(得分:3)
你最好使用
Html.RenderPartial("~/Views/Shared/_Yourpartial.cshtml")
答案 1 :(得分:2)
Html.RenderPartial("~/Views/Shared/PartialIndex.cshtml")