Copied to clipboard

Flag this post as spam?

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


  • Pinal Bhatt 298 posts 390 karma points
    Jan 20, 2011 @ 15:07
    Pinal Bhatt
    0

    Razor syntax for Model.Parent

    To my understanding "Model" object in razor syntax is equivelent to "currentPage" in xslt.

    Now I want to access the Parent of the current page/node. So I  tried to access like 

    @Model.Parent

    But I am getting following error:

    ==================================================================

    Razor Macro Engine

    An unknown error occured while rendering the following code:

    System.ArgumentNullException: A node must be provided to make a dynamic instance
    Parameter name: n
    at umbraco.MacroEngines.DynamicNode..ctor(INode n)
    at CallSite.Target(Closure , CallSite , Object )
    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
    at RazorEngine.Dynamic.cebadcaaad.Execute()
    at RazorEngine.Templating.TemplateService.Parse[T](String template, T model, String name)
    at umbraco.MacroEngines.RazorEngine.GetResult(String cacheIdentifier, String template, INode currentPage, String& result)

    Your Razor template:

    <div>
    @Model.Level
    <hr/>
    @Model.Parent.GetType().ToString()
    </div>

    ===================================================================

    Looking for help on how to access the Parent node.  

    Thanks in advance.

    Thanks & Regards,

    Pinal Bhatt

  • Pinal Bhatt 298 posts 390 karma points
    Jan 20, 2011 @ 16:03
    Pinal Bhatt
    2

    Gotcha...

    I don't know why Model.Parent does not works, but if we take this into some variable then it works fine.

    @{ var currentPg = Model; }
    <p>Level: @currentPg.Parent.Level    Name: @currentPg.Parent.Name</p>

    This way it works and we can access "Parent" page via vaiable.

Please Sign in or register to post replies

Write your reply to:

Draft