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 "";
}
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.
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);
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.
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
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);
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.
I am using umbraco 7.2.8.
Thanks
Nav
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.
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
any ideas???
Thanks
Nav
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.
Yh it is an object? It is a content picker.
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:
Hi,
That returns a null, this is what I have:
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
If you just want the node id to use is the RedirectToUmbracoPage call, just use settings.getPropertyValue
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:
is working on a reply...
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.