Razor MVC partialview pagination url action, How to determine the specified url?

Default url: http: //ipf.bulgaria.local/Aboutus.aspx

After clicking on the page url: http: //ipf.bulgaria.local/api/sitecore/Newsfeed? Page = 2

Expected URL: http: //ipf.bulgaria.local/Aboutus.aspx? Page = 2

Can anyone advise me how to achieve the expected url and how to read "/ 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>

      

+3


source to share


3 answers


This is the area of ​​MVC.



This is described in the following blog: http://sitecore.unic.com/2015/02/04/get-url-for-area-controller-action-from-a-view-rendering

0


source


Default url: http: //ipf.bulgaria.local/Aboutus.aspx

After clicking on the page url: http: //ipf.bulgaria.local/api/sitecore/Newsfeed? Page = 2

Expected URL: http: //ipf.bulgaria.local/Aboutus.aspx? Page = 2

Can anyone advise me on how to achieve the expected url and how to get read "/ api / sitecore / Newsfeed"?

Basically you want the same url always after clicking on different pages with the page number displayed as a query string.

So the first thing you need to do is pass the model as

@model PagedList.IPagedList<Type>

      



So, from your controller, you must pass the correct dataset based on the page number:

YourList.ToPagedList(pageNumber, pageSize);

      

Hence, each time you need to pass a pagenumber to the controller so that the relevant page data is passed to the view that is relevant. The question is, how do you know the page number? The paged list control gives you the page number, and you would use that to pass it as a query string and read it in the controller. so your url problem will be solved. Hope this helps, and for a better understanding see the video: https://www.youtube.com/watch?v=6bKZoKyBlE8

0


source


Although it has been asked for a while, this question might be helpful to those who are still having a problem with the generated pagination url. What you get is the default route. To solve this problem, you can add a custom route and point to it in @ Html.PagedListPager code.

But in your case, the following will do the trick:

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

      

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

0


source







All Articles