【问题标题】:Using PagedList.Mvc for partial page对部分页面使用 PagedList.Mvc
【发布时间】:2013-05-31 22:19:33
【问题描述】:

我在一页中有四个不同的选项卡,每个选项卡的数据由使用部分页面的 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 调用一样呈现下一页?

【问题讨论】:

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


    【解决方案1】:

    我将代码放在局部视图内的 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>
    

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 1970-01-01
      • 2014-10-05
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2015-01-11
      相关资源
      最近更新 更多