加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 我可以将PartialViewResult与PagedList一起使

发布时间:2020-12-16 09:47:35 所属栏目:asp.Net 来源:网络整理
导读:大家好我有一个问题,我可以在PartialViewResult Action中使用PagedList并在PartialView中显示结果吗? 这是一些代码 控制器代码: public PartialViewResult CargosPorProyecto(string id,int? page) { var cargos = db.Cargo.Include(i = i.Proyectos).Wher
大家好我有一个问题,我可以在PartialViewResult Action中使用PagedList并在PartialView中显示结果吗?

这是一些代码

控制器代码:

public PartialViewResult CargosPorProyecto(string id,int? page)
    {
        var cargos = db.Cargo.Include(i => i.Proyectos).Where(i => i.NumProyecto.Equals(id)).OrderByDescending(i => i.Fecha);

        if (Request.HttpMethod != "GET")
        {
            page = 1;
        }

        var pageSize = 10;
        var pageNumber = (page ?? 1);
        var onePage = cargos.ToPagedList(pageNumber,pageSize);


        return PartialView("ListaCargosParcial",ViewBag.OnePage = onePage);
    }

在我的PartialView中,我将此代码显示为分页

<div class="pagination-right">
    <div class="span12">
       <%: Html.PagedListPager((IPagedList)ViewBag.OnePage,page => Url.Action("CargosPorProyecto",new { page = page }),new PagedListRenderOptions { LinkToFirstPageFormat = "<< Primera",LinkToPreviousPageFormat = "< Anterior",LinkToNextPageFormat = "Siguiente >",LinkToLastPageFormat = "&Uacute;ltima >>" })%> 
    </div>                    
    </div>

当我加载包含partialview的页面时,一切看起来都不错,但是当我单击Next(“Siguiente”)时,我的局部视图中没有加载.

我希望我能清楚地解释并感谢你的时间.

问候

解决方法

如果你想留在同一页面,你可以使用AJAX.例如,如果您使用的是jQuery,则可以订阅分页链接的click事件,然后触发对相应控制器操作的AJAX请求,并使用返回的结果刷新部分:

$(function() {
    $('.pagination-right a').click(function() {
        $.ajax({
            url: this.href,type: 'GET',cache: false,success: function(result) {
                // refresh the contents of some container div for the partial
                // make sure you use the correct selector here
                $('#some_container_for_the_partial').html(result);
            }
        });

        // cancel the default action which is a redirect
        return false;
    });
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读