Jquery 使用Pagedlist分页时在新页面中呈现部分视图
延续 因此,在解决上述问题后,我添加了分页 我处理部分视图和分页的控制器方法是Jquery 使用Pagedlist分页时在新页面中呈现部分视图,jquery,asp.net-mvc-3,pagedlist,Jquery,Asp.net Mvc 3,Pagedlist,延续 因此,在解决上述问题后,我添加了分页 我处理部分视图和分页的控制器方法是 public ActionResult CreateAdmin(string sortOrder, int? page) { int pageSize = 10; int pageNumber = 1; if (page != null) pageNumber = Convert.ToInt32(page); var r
public ActionResult CreateAdmin(string sortOrder, int? page)
{
int pageSize = 10;
int pageNumber = 1;
if (page != null)
pageNumber = Convert.ToInt32(page);
var result = SortResult(sortOrder);
return PartialView("AdminSearchResult", result.ToPagedList(pageNumber, pageSize));
}
在我看来,我只是路过
@model PagedList.IPagedList<MyApplication.Models.Administration>
@model PagedList.IPagedList
动态呈现局部视图的jquery是
<script type="text/javascript">
$(document).ready(function (e) {
$("#SearchResultbtn").click(function (e) {
e.preventDefault();
$("#searchResult").load('@Url.Action("AdminSearchResult", "Administration")');
});
});
$(文档).ready(函数(e){
$(“#SearchResultbtn”)。单击(函数(e){
e、 预防默认值();
$(“#searchResult”).load('@Url.Action(“AdminSearchResult”,“Administration”));
});
});
我的视图只是一个表,如下所示
<table class="searchResult" border="1" width="100%">
<thead>
<tr>
<th>
</th>
<th>
@Html.ActionLink("Last Name", "AdminSearchResult", new { sortOrder = ViewBag.LastNameSortParm, currentFilter = ViewBag.CurrentFilter, @class = "linkClicked" })
</th>
<th>
Middle Name
</th>
<th>
@Html.ActionLink("First Name", "AdminSearchResult", new { sortOrder = ViewBag.FirstNameSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="parent">
<td>
@item.LastName
</td>
<td>
@item.MiddleName
</td>
<td>
@item.FirstName
</td>
</tr>
}
</tbody>
</table>
@ActionLink(“姓氏”,“AdminSearchResult”,新{sortOrder=ViewBag.LastNameSortParm,currentFilter=ViewBag.currentFilter,@class=“linkClicked”})
中名
@ActionLink(“名字”,“AdminSearchResult”,新的{sortOrder=ViewBag.FirstNameSortParm,currentFilter=ViewBag.currentFilter})
@foreach(模型中的var项目)
{
@item.LastName
@item.MiddleName
@item.FirstName
}
我的分页和排序工作正常。问题是,当我点击“名字”的ActionLink或任何用于排序的听者时,整个部分视图都会呈现在新页面中
我的猜测是jquery需要更新,但是如何更新。从您提到的行为来看,我认为您只需要这样的东西:
@Ajax.ActionLink("First Name", "AdminSearchResult", new { sortOrder = ViewBag.FirstNameSortParm, currentFilter = ViewBag.CurrentFilter }, new AjaxOptions { UpdateTargetId = "searchResult" }, null)
基本上是对页面进行部分更新,而不是整页刷新
要在MVC中成功地使用ajax方法,您需要执行以下操作。将此密钥添加到web.config中的appsettings:
<appSettings>
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
还包括不引人注目的ajax脚本:
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
从你提到的行为来看,我认为你只需要这样的东西:
@Ajax.ActionLink("First Name", "AdminSearchResult", new { sortOrder = ViewBag.FirstNameSortParm, currentFilter = ViewBag.CurrentFilter }, new AjaxOptions { UpdateTargetId = "searchResult" }, null)
基本上是对页面进行部分更新,而不是整页刷新
要在MVC中成功地使用ajax方法,您需要执行以下操作。将此密钥添加到web.config中的appsettings:
<appSettings>
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
还包括不引人注目的ajax脚本:
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
嘿,莫比。再次感谢您的回复。不,它不起作用。当我单击“名字”进行排序时,部分视图将在新页面中打开。页面上是否有脚本中包含的不引人注目的AJAX或MVC AJAX?不,我没有。我应该包括它吗?是的,在MVC中使用AJAX助手时需要它。我为你更新了我的答案。哦,我明白了。因此,添加上述设置与将控件放入Updatepanel中以在asp.net中进行部分更新相同???。嘿,Moby。再次感谢您的回复。不,它不起作用。当我单击“名字”进行排序时,部分视图将在新页面中打开。页面上是否有脚本中包含的不引人注目的AJAX或MVC AJAX?不,我没有。我应该包括它吗?是的,在MVC中使用AJAX助手时需要它。我为你更新了我的答案。哦,我明白了。因此,添加上述设置与在asp.net???中将控件放在Updatepanel中进行部分更新相同???。。