none
Using MVC PagedList in Provider Hosted Add-in RRS feed

  • Question

  • Hi,

    In my Provider Hosted Add-in developed by MVC 5 Razor, I have used PagedList on one of the index views. T

    The paging is working fine on that page but on the left menu, the item links are coming like- https://site.com/product. But, the link should be like- https://appweb.com/product?SPHostUrl=https://hostweb.com/...... The host url part is missing here. For this reason, when I navigate to another page through the menu from the paged view, it generates error as the menu item doesn't contain host url part (?SPHostUrl=https://hostweb.com/.....). From non-paged list, the menu is working fine as it contains the host url part (?SPHostUrl=https://hostweb.com/.....) with the page url. Menu items are like-

    <li class="active">@Html.ActionLink("Products", "Index", "ProductList")</li>
    Any idea how to resolve this? Thanks.

    Friday, May 25, 2018 6:34 AM

Answers

  • Hi,

    1. Add Controller Action:

    [SharePointContextFilter]

    2. Generate the ActionLink with SPHostUrl like below:

    <li>@Html.ActionLink("Install Design Package", "InstallDesignPackage", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Current.Request).AbsoluteUri },null)</li>

    Same question specified in StackOverFlow for your reference:

    How to append sharepoint required parameters for APPS, in asp.net mvc apps?

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by pointtoshare Tuesday, May 29, 2018 3:10 AM
    Monday, May 28, 2018 10:14 AM

All replies

  • Hi,

    1. Add Controller Action:

    [SharePointContextFilter]

    2. Generate the ActionLink with SPHostUrl like below:

    <li>@Html.ActionLink("Install Design Package", "InstallDesignPackage", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Current.Request).AbsoluteUri },null)</li>

    Same question specified in StackOverFlow for your reference:

    How to append sharepoint required parameters for APPS, in asp.net mvc apps?

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by pointtoshare Tuesday, May 29, 2018 3:10 AM
    Monday, May 28, 2018 10:14 AM
  • Hi Jerry,

    Thanks for your reference, it works but when I filter item on the page, it generates the following error-

    System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[ProductManagementWeb.Models.Product]', but this dictionary requires a model item of type 'PagedList.IPagedList`1[ProductManagementWeb.Models.Product]'.

    Would be great if you please guide further. Thanks.

    Monday, May 28, 2018 11:04 AM
  • Hi,

    Glad to hear that it is working for you. I would suggest you can Mark it as answer if it helps so that it could help others who stuck with the same issue in the forum.

    About the new error message, this is related to MVC part, please check if the returned the view with.ToPagedList:

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`,

    And here is a demo about about using Paged List in MVC Application for your reference:

    https://www.c-sharpcorner.com/article/paging-in-asp-net-mvc-4-using-pagelist/

    And about MVC Related issue, I would suggest you can create a new thread in MVC Forum which will focus on MVC Related Development:

    https://forums.asp.net/1146.aspx/1?MVC

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.



    Monday, May 28, 2018 11:30 AM