Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 161 posts 426 karma points
    Jun 09, 2016 @ 17:26
    Naveed Ali
    0

    Getting node by picker

    Hi

    I am trying to get a node from a content picker which is in my settings tab.

    I am then wanting to get absolute URL etc as this is to be sent to a new member by email

    this is my code but "page" is always null.. any idea how else I can get the node without hacking in by using node id. As i need to give client flexibility to change this page by a picker.

     protected string GetUrl (string key)
            {
                //var page = Umbraco.TypedContentSingleAtXPath("//register");    
                //var page = Umbraco.TypedContentSingleAtXPath("//RegistrationPartTwo");
    
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                var settings = umbracoHelper.TypedContentSingleAtXPath("//Settings"); ;
                var page = settings.GetPropertyValue<IPublishedContent>("registrationLink");
    
                if (page != null)
                {
                    var resetLink = page.UrlAbsolute() + "?key=" + HttpUtility.UrlEncode(key);
                    var tagBuilder = new System.Web.Mvc.TagBuilder("a");
                    tagBuilder.Attributes.Add("href", resetLink);
                    tagBuilder.InnerHtml = "Registration";
                    return tagBuilder.ToString();
                }
                return "";
            }
    

    I am using umbraco 7.2.8.

    Thanks

    Nav

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jun 09, 2016 @ 21:54
    Nathan Woulfe
    0

    Hi Nav

    Pretty sure the value returned by settings.GetPropertyValue("registrationLink") will be the ID of the node selected in the picker.

    Rather than trying to return it as IPublishedContent, return an int value instead, and use umbracoHelper.TypedContent(id) to fetch the node, which will be of type IPublishedContent.

  • Naveed Ali 161 posts 426 karma points
    Jun 10, 2016 @ 00:50
    Naveed Ali
    0

    Hi Nathan,

    This is what I have so far but still no luck. I get an error that id must be integer or string even tho i already have declared it as an int

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var settings = umbracoHelper.TypedContentSingleAtXPath("//LoginPage"); ;
            var page = settings.GetPropertyValue("confirmationPage");
            int pageId = Umbraco.Content(page).id;
    
            return RedirectToUmbracoPage(pageId);
    

    any ideas???

    Thanks

    Nav

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jun 10, 2016 @ 01:07
    Nathan Woulfe
    0

    Depending on which picker data type you're using the value might be an object, not a simple integer - check what is returned from the property and extract the node id from that.

  • Naveed Ali 161 posts 426 karma points
    Jun 10, 2016 @ 01:09
    Naveed Ali
    0

    Yh it is an object? It is a content picker.

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jun 10, 2016 @ 01:30
    Nathan Woulfe
    0

    A content picker will return the node id (ignore my previous comment, we use a third-party picker which returns a different value).

    This should return the registration node:

    var registrationNode = umbracoHelper.TypedContent(settings.GetPropertyValue<int>("registrationLink"));
    
  • Naveed Ali 161 posts 426 karma points
    Jun 10, 2016 @ 10:45
    Naveed Ali
    0

    Hi,

    That returns a null, this is what I have:

     var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                var settings = umbracoHelper.TypedContentSingleAtXPath("//LoginPage"); ;
    
                var pageId = umbracoHelper.TypedContent(settings.GetPropertyValue<int>("confirmationPage"));
                return RedirectToUmbracoPage(pageId);
    

    This is getting really frustrating its so simple to get it in razor why so hard in a controller, also done some googling cannot see no info on this

    Thanks

    Nav

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jun 10, 2016 @ 12:36
    Nathan Woulfe
    0

    If you just want the node id to use is the RedirectToUmbracoPage call, just use settings.getPropertyValue

  • Naveed Ali 161 posts 426 karma points
    Jun 10, 2016 @ 13:50
    Naveed Ali
    0

    Hi Nathan,

    I already tried that at begining of this thread, or I may be missing something is there any chance you can show me sample code??

    This is what I have by what you have said and I get an error under redirectumbracopage:

     var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var settings = umbracoHelper.TypedContentSingleAtXPath("//LoginPage"); ;           
            var id = settings.GetPropertyValue("confirmationPage");
    
     return RedirectToUmbracoPage(id);
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies