Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Aug 30, 2021 @ 10:58
    Owain Williams
    0

    Pagination not working via Ajax call

    Hi, I've got a bug in my sitye where I am passing the current page Id to the indexer. The reason I'm doing this is so I return only the blogs from a specific site. I'm hosting 2 sites on one instance of Umbraco.

    On the initial load the correct blogs are shown and all is good, however, when I call this method via ajax I get an error.

    umbracoHelper.AssignedContentItem.Id = 'umbracoHelper.AssignedContentItem.Id' threw an exception of type 'System.InvalidOperationException'

    I'm presuming this is because it's an ajax call but I can't figure out how to get this working.

    enter image description here

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 30, 2021 @ 11:15
    Nik
    2

    Ajax requests don't generally have an assigned content item on the Umbraco helper. You are better off passing the key of the page as part of the request.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Aug 30, 2021 @ 15:04
    Owain Williams
    0

    A great, of course! Thanks.

    Now passing the value from @Umbaco.AssignedContentItem.Id to my javascript which then passes the value to my controller.

    Cheers! O.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Aug 30, 2021 @ 15:24
    Owain Williams
    0

    Is there a way to have a fallback so if Umbraco.AssignedContentItem.id isn't valid due to it being a ajax request then use Model.CurrentPageId?

    Reason I ask is, on initial page load, Umbraco.AssignedContentItem.Id works. This means I can then take the id and post it via a model and ajax to my pagination method.

    But then when the pagination loads the page, Umbraco.AssignedContentItem.Id throws an error because it's not got a value but now Model.CurrentPageId does.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Aug 30, 2021 @ 18:36
    Owain Williams
    0

    Changed my approach and it now works.

    Just had to walk away from the screen and get some food.

    I'll blog about how I fixed the issue.

Please Sign in or register to post replies

Write your reply to:

Draft