Copied to clipboard

Flag this post as spam?

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


  • Kyle Eck 7 posts 77 karma points
    Apr 08, 2019 @ 15:51
    Kyle Eck
    0

    Umbraco 8 get IPublishedContent node without hardcoding the id

    How would I go about getting an IPublishedContent node without hard coding the id of the page?

    I am making an AJAX call to update a partial view and lose Umbraco context, therefore I cannot use something like AssignedContentItem.

    Basically I have the below:

    IPublishedContent node = this.UmbracoContext.ContentCache.GetById(CurrentPage.Id);

            var currentUser = Umbraco.MembershipHelper.GetCurrentMember();
            var currentUserWelcome = node.GetProperty("profileWelcome") + currentUser.Name + "!";
    
    
            var model = new Profile
            {
                WelcomeTitle = currentUserWelcome
            };
    
            return PartialView(LAYOUT_DIRECTORY + "_YourProfile.cshtml");
    

    I want to dynamically get the corresponding page so that if it were to move in the back office or the id were to change it would not break.

    Thanks

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Apr 08, 2019 @ 16:11
    Søren Gregersen
    0

    I would just include the id in the request for your action.

    public class SomethingSurfaceController{
        public object YourProfile(int page){
            var node = Umbraco.Content(page);
            [...]
        }
    }
    

    HTH :)

  • Kyle Eck 7 posts 77 karma points
    Apr 09, 2019 @ 12:23
    Kyle Eck
    0

    So you are saying pass the page along as a parameter in my ActionResult Signature?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Apr 09, 2019 @ 12:33
    Søren Gregersen
    0

    yes

    use that page-parameter to find the node with your content

Please Sign in or register to post replies

Write your reply to:

Draft