我使用无限滚动进行分页。它一直工作到今天。今天我决定在我的所有动作方法中添加两个额外的参数,现在使用无限滚动的指向动作方法出错了 因此,当我滚动页面时,不会调用动作 所以我打开页面源并找到应该加载下一页的链接,它看起来像:
href="/Tickets/AnotherSetOfData?countryCode=uk&cityName=london&ticketTypeId=-1"
如果我点击此链接动作方法被调用,那么问题是无限滚动以某种方式停止在滚动时调用此函数。
这就是动作方法的样子
public ActionResult AnotherSetOfData(string countryCode, string cityName, int ticketTypeId)
{...}
我怀疑这可能是路由问题,但我不知道如何处理它...
路由
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
无限滚动
<nav id="page-nav">
<a href="@Url.Action("AnotherSetOfData", "Tickets", new { countryCode = ViewBag.countryCode, cityName = ViewBag.cityName, ticketTypeId = ViewBag.ticketTypeId })">
</a>
</nav>
...
$container.infinitescroll({
navSelector: '#page-nav', // selector for the paged navigation
nextSelector: '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector: '.item', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
function (newElements) {
var $newElems = $(newElements).css({ opacity: 0 });
$newElems.imagesLoaded(function () {
$newElems.animate({ opacity: 1 });
$container.isotope('appended', $newElems);
});
答案 0 :(得分:1)
将它放在Global.asax.cs
中routes.MapRoute(
"InfiniScroll", // Route name
"{controller}/{action}/{countryCode}/{cityName}/{ticketTypeId}", //URL with parameters
new { controller = "Tickets", action = "AnotherSetOfData"}); // Parameter Defaults