我在一个页面中有四个不同的选项卡,每个选项卡的数据是通过使用部分页面的 ajax 调用呈现的。选项卡的数据由 ajax post 加载。 Ajax 调用:
$('#movieDatabase').click(function () {
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'html',
type: 'POST',
url: '/Admin/GetMovieDatabase',
data: {},
success: function (data) {
$('#view16').html(data);
},
failure: function (response) {
alert('error');
$('#view16').html(response);
}
});
});
此 ajax 调用呈现了部分页面。现在我想做的是对来自数据库的电影进行分页。为此我使用 PagedList.Mvc。但将电影从一页导航到另一页时出现问题。它是通过以下方式完成的:
@Html.PagedListPager((IPagedList)Model.MovieInforamtions, page => Url.Action("GetMovieDatabase", new { page }))
但是当我单击下一页时,它会给出页面未找到错误,因为我没有在 HTTPGet 中编写任何操作。如果我通过 HTTPGet 进行上述调用,我将无法渲染所有页面,而只能渲染部分页面。我的行动是..
[HttpPost]
public ActionResult GetMovieDatabase(int? page)
{
var AdminGetMovieDatabaseViewModel = new AdminGetMovieDatabaseViewModel();
var allMovie = _AdminService.getAllMovieInfo();
var pageNumber = page ?? 1;
// if no page was specified in the querystring, default to the first page (1)
var onePageOfMovie = allMovie.ToPagedList(pageNumber, 5);
// will only contain 5 products max because of the pageSize
AdminGetMovieDatabaseViewModel.MovieInforamtions = onePageOfMovie;
return PartialView("MovieDataBasePartialPage", AdminGetMovieDatabaseViewModel);
}
现在我怎样才能像之前完成的ajax调用一样渲染下一页?
最佳答案
我将代码放在部分 View 内的 javascript 部分中,并且对我有用。
<script language ="javascript" type="text/javascript">
$('#movieDatabase').click(function () {
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'html',
type: 'POST',
url: '/Admin/GetMovieDatabase',
data: {},
success: function (data) {
$('#view16').html(data);
},
failure: function (response) {
alert('error');
$('#view16').html(response);
}
});
});
</script>
关于asp.net-mvc - 使用PagedList.Mvc进行部分页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16936150/