Copied to clipboard

Flag this post as spam?

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


  • yumin 51 posts 243 karma points
    Jan 08, 2014 @ 10:51
    yumin
    0

    how to get CurrentPage in @functions method

        @functions {
            public static string Getxxx()
            {
                 var homePage = CurrentPage.AncestorsOrSelf(1).First();
            }
        }
    

    it will get a error, how to get CurrentPage?

    thanks very much

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 08, 2014 @ 12:01
    Jeroen Breuer
    100

    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

  • yumin 51 posts 243 karma points
    Jan 09, 2014 @ 04:32
    yumin
    0
     @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

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Jan 09, 2014 @ 11:42
    Jeroen Breuer
    0

    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

  • yumin 51 posts 243 karma points
    Jan 14, 2014 @ 03:31
    yumin
    0

    thanks jeroen, it works

  • 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