MVC PagedList 向服务器发送奇怪的请求
MVC PagedList sending weird requests to server
我将 MVC 与 PagedList 结合使用,以便将一个大 table 分成多个页面。
现在,在网络浏览器中,这是我看到的:
http://localhost:49370/Home/Pending?page=2
这是有道理的。但是,当向服务器发送请求时,服务器收到的是:http://localhost:49370/Home/WhereAmI?_=1429091783507
这是一团糟,反过来又无法将用户重定向到列表中的特定页面,因为我不知道用户当前正在查看的页面是什么!
控制器代码:
public ActionResult Pending(int? page)
{
//I have a ViewModel, which is MaterialRequestModel
IEnumerable<MaterialRequestModel> model = DB.GATE_MaterialRequest
.Select(req => new MaterialRequestModel(req))
.ToList();
int pageNum = page ?? 1;
return View(model.ToPagedList(pageNum, ENTRIES_PER_PAGE));
}
查看代码:
@model IEnumerable<MaterialRequestModel>
<table>
//table stfuff
</table>
<div style="display: block;text-align: center">
@Html.PagedListPager((PagedList.IPagedList<MaterialRequestModel>)Model, page => Url.Action("Pending", new { page }), PagedListRenderOptions.ClassicPlusFirstAndLast)
</div>
这是 MVC PagedList 的限制吗?还是我遗漏了什么?
碰巧PagedList不会向服务器发送这类信息。相反,如果您想知道正在查看哪个页面,则必须使用具有该信息的自定义模型,如果您想发出请求,请使用 ajax(此处为原始 objective)您必须使用特殊选项:
@Html.PagedListPager(Model.requests, page => Url.Action("SearchTable", "Home",
new
{
employeesQuery = Model.query.employeesQuery, //your query here
pageNum = page
}
), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "tableAndPaginationDiv", OnComplete = "initiatePendingTableDisplay" }))
诚然,这个解决方案充其量也很差。您只能在整个列表中选择一个选项(因此,如果您已经在其他地方使用了其他选项,您可以忘记它)并且您无法控制所提出的请求,因此自定义在这里真的不是一个选项,除非您想要挂钩电话。
无论如何,这就是我修复它的方式,希望它能对以后的人有所帮助!
我将 MVC 与 PagedList 结合使用,以便将一个大 table 分成多个页面。
现在,在网络浏览器中,这是我看到的: http://localhost:49370/Home/Pending?page=2
这是有道理的。但是,当向服务器发送请求时,服务器收到的是:http://localhost:49370/Home/WhereAmI?_=1429091783507
这是一团糟,反过来又无法将用户重定向到列表中的特定页面,因为我不知道用户当前正在查看的页面是什么!
控制器代码:
public ActionResult Pending(int? page)
{
//I have a ViewModel, which is MaterialRequestModel
IEnumerable<MaterialRequestModel> model = DB.GATE_MaterialRequest
.Select(req => new MaterialRequestModel(req))
.ToList();
int pageNum = page ?? 1;
return View(model.ToPagedList(pageNum, ENTRIES_PER_PAGE));
}
查看代码:
@model IEnumerable<MaterialRequestModel>
<table>
//table stfuff
</table>
<div style="display: block;text-align: center">
@Html.PagedListPager((PagedList.IPagedList<MaterialRequestModel>)Model, page => Url.Action("Pending", new { page }), PagedListRenderOptions.ClassicPlusFirstAndLast)
</div>
这是 MVC PagedList 的限制吗?还是我遗漏了什么?
碰巧PagedList不会向服务器发送这类信息。相反,如果您想知道正在查看哪个页面,则必须使用具有该信息的自定义模型,如果您想发出请求,请使用 ajax(此处为原始 objective)您必须使用特殊选项:
@Html.PagedListPager(Model.requests, page => Url.Action("SearchTable", "Home",
new
{
employeesQuery = Model.query.employeesQuery, //your query here
pageNum = page
}
), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "tableAndPaginationDiv", OnComplete = "initiatePendingTableDisplay" }))
诚然,这个解决方案充其量也很差。您只能在整个列表中选择一个选项(因此,如果您已经在其他地方使用了其他选项,您可以忘记它)并且您无法控制所提出的请求,因此自定义在这里真的不是一个选项,除非您想要挂钩电话。
无论如何,这就是我修复它的方式,希望它能对以后的人有所帮助!