在局部视图使用分页,asp.net的MVC [英] Using paging in partial view, asp.net mvc

查看:290
本文介绍了在局部视图使用分页,asp.net的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会非常AP preciate如果有人能提出建议如下:
在我看来,我显示的项目清单:

I'd greatly appreciate if someone could advise on following: In my view I display the list of items:

@model PagedList.IPagedList<Items>
@using PagedList.Mvc; 
 @foreach (var item in Model)
          {//displaying data}

我的传呼机是这样的:

my pager looks like this:

@Html.PagedListPager(Model, page => Url.Action("Index", new { humanID = ViewBag.HumanID, page = page }),
                                                             new PagedListRenderOptions
                                                             {
                                                                        LinkToFirstPageFormat = "<<",
                                                                        LinkToPreviousPageFormat = "prev",
                                                                        LinkToNextPageFormat = "next",
                                                                        LinkToLastPageFormat = ">>",

                                                              })

问题是,当我点击下页则返回空白,没有我的 _layout 。我不想重装_layout所有的时间。有没有办法使用Ajax.ActionLink寻呼机的方法吗?这样我就可以 UpdateTargedId 我的局部视图里面呢?

The problem is that when I click on the next page it is returned blank, without my _Layout. I wouldn't like to reload _Layout all the time. Is there a way to use Ajax.ActionLink for pager? So that I could UpdateTargedId inside my partial view?

推荐答案

您不能使用Ajax.ActionLink但是你可以AJAXify的链接。把寻呼机在&LT; D​​IV&GT;

You cannot use Ajax.ActionLink but you could AJAXify the links. Put the pager in a <div>:

<div id="myPager">
    @Html.PagedListPager(
        Model, 
        page => Url.Action(
            "Index", 
            new { 
                humanID = ViewBag.HumanID, 
                page = page 
            }
        ),
        new PagedListRenderOptions
        {
            LinkToFirstPageFormat = "<<",
            LinkToPreviousPageFormat = "prev",
            LinkToNextPageFormat = "next",
            LinkToLastPageFormat = ">>",
        }
    )
</div>

然后AJAXify链接:

and then AJAXify the links:

$(function() {
    $('#myPager').on('click', 'a', function() {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function(result) {
                $('#some_grid_container').html(result);
            }
        });
        return false;
    });
});

请注意,在的成功,我已经使用 $('#some_grid_container') 的回调应该是一些包装DIV整个表格左右。

Notice that in the success callback I've used $('#some_grid_container') which should be some wrapping div around your entire table.

这篇关于在局部视图使用分页,asp.net的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆