Copied to clipboard

Flag this post as spam?

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


  • Thomas Won Nyheim 33 posts 145 karma points
    Mar 07, 2018 @ 15:15
    Thomas Won Nyheim
    0

    Getting CurrentPage in WebApi

    Is there a way of getting the CurrentPage or nodeId within the WebApi controller, without sending it through the ajax call?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 07, 2018 @ 15:53
    Alex Skrypnyk
    100

    Hi Thomas

    There is no CurrentPage when you call WebAPI

    You can't get current page when you call WebAPI via js, you have to specify current page id via parameter passed

    Alex

  • Thomas Won Nyheim 33 posts 145 karma points
    Mar 08, 2018 @ 10:05
    Thomas Won Nyheim
    0

    Thank you.

    This is what I was trying to figure out. Didn't know if there was some magical way that I just couldn't find, so that I could drop sending it through the ajax call.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Mar 07, 2018 @ 16:28
    Steve Morgan
    0

    Often it's easier to just get the root node of the site and then "find" the node you want from there. Or hardcode the ID.

    Umbraco.TypedContentAtRoot().First();
    
  • Thomas Won Nyheim 33 posts 145 karma points
    Mar 08, 2018 @ 10:07
    Thomas Won Nyheim
    0

    Hello, thank you for replying.

    I need to figure out the exact page that sent the request, so I wouldn't know which instance of the document it would be, as searching from root could result in multiple documents matching the same criteria unless I specify the ID.

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Mar 09, 2018 @ 11:15
    Steve Morgan
    0

    I've not tried this but would you be happy sending the URL of the current page in the request?

    Then you could do (according to a quick Google - there might be a better way!)

    UmbracoContext.Current.ContentCache.GetByRoute(string url)

  • Thomas Won Nyheim 33 posts 145 karma points
    Mar 09, 2018 @ 11:40
    Thomas Won Nyheim
    0

    Hello again,

    I was trying to avoid sending it through parameteres in the request, as I feel it is unnecessary information to have in the front-end code.

    However it was the solution I ended up doing, as of what I've researched there would be no other way as of now.

Please Sign in or register to post replies

Write your reply to:

Draft