Umbraco 7 mvc how to get current page id

I have a custom controller to send a message. Therefore, I need to get the value of the property field name and alias = "email", this will be used to send email.

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 that if the page name changes, the URL will change and the code will break.

So, how can I modify the above code to get the current page id and paste it here (???) ;?

I think the code should be something like this:

 IPublishedContent root = Umbraco.TypedContent(???);
 return root.GetProperty("email", true).Value.ToString();

Any help would be appccciated

+4
source share
2 answers

, 1 "ContactUs" node . , .

( node, - ...)

? :

IPublishedContent currentNode = Umbraco.TypedContent(CurrentPage.Id)
+9

, .

var nodes = umbraco.uQuery.GetNodesByType("ContactUs");
if (nodes.Any())
{
   IPublishedContent node = Umbraco.TypedContent(nodes.First().Id);
   return node.GetProperty(property, true).Value.ToString();
}

, - .

+2

Source: https://habr.com/ru/post/1537426/


All Articles