I have a custom controller to send message. So I need to get the value of property field name and alias = "email", this will be used to send the email to.
this code below works
var id = umbraco.uQuery.GetNodeByUrl("/contact-us");
IPublishedContent root = Umbraco.TypedContent(id.Id);
return root.GetProperty("email", true).Value.ToString();
However the problem here is if the page name changes, the url will change and the code will break.
So how can I change the code above to get the current page id and insert it here (???);?
I think the code should be something like this:
IPublishedContent root = Umbraco.TypedContent(???);
return root.GetProperty("email", true).Value.ToString();
Any help will be apprecciated
Your solution will bring a problem if you have more than 1 'ContactUs' node, or none. Then you don't know which one is going to be get.
(Actually it's the first one found in the node tree, but then someone can change the order of them...)
Is your controller a Surface controller? You can just do this:
IPublishedContent currentNode = Umbraco.TypedContent(CurrentPage.Id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With