asp.net-mvc - 使用PagedList.Mvc进行部分页面

标签 asp.net-mvc asp.net-mvc-3 asp.net-ajax

我在一个页面中有四个不同的选项卡,每个选项卡的数据是通过使用部分页面的 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/

相关文章:

javascript - 单击时禁用 asp.net 按钮

c# - 在 3 个实体之间创建导航属性

javascript - MVC 4 中的数据注释不显示错误消息

c# - 上传 Excel 工作表并将数据导入 SQL Server Express 数据库

asp.net-mvc - 使用 MongoDB 托管 ASP.NET MVC 3 应用程序

c# - 像谷歌地方一样切换按钮

asp.net-mvc - 没有值(value)的asp.net mvc htmlattribute

asp.net-mvc - ASP.NET MVC 2 RC2 路由 - 使用 ActionLink 引用更高级别时如何清除低级别值?

asp.net-mvc - Html.Textbox VS Html.TextboxFor

javascript - 从 JavaScript 添加 asp.net 下拉列表项导致页面回发错误