Razor MVC部分视图分页url操作,如何定义指定的url? [英] Razor MVC partialview pagination url action, How to define specified url?

查看:224
本文介绍了Razor MVC部分视图分页url操作,如何定义指定的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认网址: http://ipf.bulgaria.local/Aboutus. aspx

点击分页网址后: http://ipf.bulgaria.local/api/sitecore/Newsfeed?page = 2

预期的网址: http://ipf.bulgaria. local/Aboutus.aspx?page = 2

有人可以建议我如何实现预期的网址以及如何阅读"/api/sitecore/Newsfeed"吗?

Can someone advice me how to achieve the expected url and how to get read of "/api/sitecore/Newsfeed"?

<div class="col-sm-10">
    <div class="center">        
            @Html.PagedListPager((PagedList.IPagedList)Model
            .SelectedNewsItems, 
            page => Url.Action("Index", new { page }))
    </div>
</div>

推荐答案

尽管这个问题已经有一段时间了,但对于那些仍然对所生成的分页URL仍有疑问的人来说,它可能是有用的.您得到的是默认路由.要解决此问题,可以在代码@ Html.PagedListPager中添加一个自定义路由并指向它.

Even though it has been a while this question is asked, it may be useful for those who are still having an issue with the generated pagination URL's. What you are getting is the default route. To solve it, you can add a custom route and point to it in the code @Html.PagedListPager.

但是在您的情况下,以下方法可以解决问题:

But in your case the following will do the trick:

@Html.PagedListPager(Model, page => 
LinkManager.GetItemUrl(Sitecore.Context.Item) + "?page=" + page)

LinkManager.GetItemUrl(Sitecore.Context.Item)部分将获取当前项目的URL.这样,您将按预期获得"Aboutus.aspx?page = 2" URL.

The part LinkManager.GetItemUrl(Sitecore.Context.Item) will get the URL of the current item. This way you will get "Aboutus.aspx?page=2" URL as expected.

这篇关于Razor MVC部分视图分页url操作,如何定义指定的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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