使用ajax选项时,如何在PagedListPager中使用PagedListRenderOptions?

时间:2016-10-02 06:53:28

标签: asp.net asp.net-mvc

使用ajax选项时如何在PagedListRenderOptions中使用PagedListPager

@Html.PagedListPager((IPagedList)Model, page =>
 Url.Action("AllProducts", "Products", new { page }),
 PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "productsContent", OnBegin = "onBeginLoader", OnComplete = "onComplete" }))

我想要修改这样的东西:

@Html.PagedListPager((IPagedList)ViewBag.posts, page =>
 Url.Action("Index", new { page = page }), new PagedListRenderOptions 
{ LinkToFirstPageFormat = "<< ابتدا", LinkToPreviousPageFormat = "< قبلی", LinkToNextPageFormat = "بعدی>", LinkToLastPageFormat = "آخرین >>" })

3 个答案:

答案 0 :(得分:0)

您可以使用以下

    @Html.PagedListPager((IPagedList)ViewBag.posts, 
                          page => Url.Action("Index", page }),
                        PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
                                            LinkToFirstPageFormat = "", 
                                            LinkToLastPageFormat = "آخرین >>",
                        new AjaxOptions(){  HttpMethod = "GET", 
                                            UpdateTargetId = "YourTarget",}))

这里有关于如何使用Ajax PagedList的sample

希望这会对你有所帮助

答案 1 :(得分:0)

我做到了。 要自定义为fllow:

Html.PagedListPager((IPagedList)Model, page => Url.Action("AllProducts", "Products",new { page }), 
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
new PagedListRenderOptions { LinkToFirstPageFormat = " ابتدا", LinkToPreviousPageFormat = " قبلی", LinkToNextPageFormat = "بعدی", LinkToLastPageFormat = "آخرین " }, new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "productsContent", OnBegin = "onBeginLoader", OnComplete = "onComplete" }))

答案 2 :(得分:0)

在Asp.Net核心剃须刀页面中

 @Html.PagedListPager(Model.Trainings,
                   pageNumber => Url.Page("/Training/TrainingList", new {
                       PageNumber = pageNumber,
                       SortBy=Model.SortBy,
                       Search=Model.Search,
                       StartDate=Model.StartDate,
                       Type=Model.Type,
                       TotalCount= Model.Trainings.TotalItemCount
                   }),
                   X.PagedList.Mvc.Common.PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions {
                       OnSuccess="onSuccess",
                       OnFailure ="onFailure",
                       HttpMethod = "GET",
                       UpdateTargetId = "TrainingList",
                       LoadingElementId = "loadingProgress"
                   }))

如果不输入UpdateTargetId,则会得到->语法错误,无法识别的表达式:#exception

TrainingList是我们获取数据的另一页

从页面返回部分视图结果

var myViewData = new ViewDataDictionary(new Microsoft.AspNetCore.Mvc.ModelBinding.EmptyModelMetadataProvider(),新Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary()){{“ PaginationModel”,PaginationModel}};                 myViewData.Model = PaginationModel;

            PartialViewResult partialViewResult = new PartialViewResult
            {
                ViewName = "_PagedTraining",
                ViewData = myViewData,

                ContentType = "text/html; charset=utf8"
            };

_PagedTraining-部分视图