Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
@functions { public static string Getxxx() { var homePage = CurrentPage.AncestorsOrSelf(1).First(); } }
it will get a error, how to get CurrentPage?
thanks very much
If it's a new Razor file than you should replace CurrentPage with Model.Content. In Controllers the current node is CurrentPage and in views it's Model.Content.
Jeroen
@functions { public static string Getxxx() { var homePage = Model.Content.AncestorsOrSelf(1).First(); } }
thanks for quickly reply,I try this code buy get a error
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Hmm where are you placing this code? If it's a view that has @inherits Umbraco.Web.Mvc.UmbracoTemplatePage on top it should work.
thanks jeroen, it works
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
how to get CurrentPage in @functions method
it will get a error, how to get CurrentPage?
thanks very much
If it's a new Razor file than you should replace CurrentPage with Model.Content. In Controllers the current node is CurrentPage and in views it's Model.Content.
Jeroen
thanks for quickly reply,I try this code buy get a error
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Hmm where are you placing this code? If it's a view that has @inherits Umbraco.Web.Mvc.UmbracoTemplatePage on top it should work.
Jeroen
thanks jeroen, it works
is working on a reply...