【问题标题】:Helper for PagedList supporting unobtrusive Ajax in ASP.NET MVC在 ASP.NET MVC 中支持不显眼的 Ajax 的 PagedList 助手
【发布时间】:2012-06-19 00:27:40
【问题描述】:

我目前正在使用 PagedList (https://github.com/TroyGoode/PagedList/) 来管理我在 ASP.NET MVC 应用程序中的分页。

从今天开始,我已经开始将应用程序的某些部分转换为使用 AJAX,ASP.NET MVC 让这变得非常容易。

然而,我遇到的第一个问题是 PagedList.MVC 助手 @Html.PagedListPager 与不显眼的 AJAX 完全不兼容。

我真正需要做的就是为分页链接添加一些属性(见下文),其余的将自动处理。然而,PagedListPager 没有提供任何方法来做到这一点。

data-ajax="true" data-ajax-mode="replace" data-ajax-update="#SearchResults" 

有没有人遇到过这个问题并找到了一个优雅的解决方案?

【问题讨论】:

标签: asp.net-mvc pagination pagedlist


【解决方案1】:

我添加了对不显眼的 AJAX 的支持:

https://github.com/TroyGoode/PagedList/issues/26#issuecomment-6471793

【讨论】:

【解决方案2】:

我相信这可能是最优雅的解决方案。

@Html.PagedListPager((IPagedList)Model.Articles, page => Url.Action("Index", new { s = Model.SearchString, page = page }))

<script>


    var pages = $('#pages a[href^="/"]');

    pages.attr('data-ajax', 'true')
        .attr('data-ajax-mode', 'replace')
        .attr('data-ajax-update', '#SearchResults')
        .attr('data-ajax-method', 'post');


</script>

快速 jQuery hack 为所有链接添加必要的属性,以便它们被不显眼的 ajax 模块拾取。

[href^="/"] 部分确保只有可点击的链接会被修改。如果你不使用这个,灰色的上一个链接将是可点击的。

【讨论】:

猜你喜欢
  • 2012-12-28
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
  • 2015-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多