Copied to clipboard

Flag this post as spam?

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


  • Raghav 34 posts 103 karma points
    Jan 05, 2015 @ 07:58
    Raghav
    0

    Accessing CurrentPage and its related properties in UmbracoViewPage with customobject(Not inheriting from Render Model)

    Hi,

    The scenario is as follows.

     

    I have a custom model being returned from service so it cannot be inherited from Render Model

    To get the custom model working ,the @inherits needs to be changed to UmbracoViewPage<custommodel> from UmbracoTemplate 

    When this is done , I am not able to access CurrentPage and its related properties. Note- I cannot make my custom object inherit from RenderModel since the object being returned from the service is outside Umbraco context and would not be a good to add it over here.

    I understand UmbracoTemplate class has those properties but what is the alternative.

    Regards

     Raghav

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 05, 2015 @ 08:17
    Dennis Aaen
    0

    Hi Raghav and welcome to our,

    I think when you are using the UmbracoViewPage, you are in a strongly typed context then you need to access the properties like @Model.Content, and if you for intance need the page name you could do.

    @Model.Content.GetPropertyValue("Name") or @Model.Content.GetPropertyValue<string>("Name").

    Hope this helps,

    /Dennis

  • Raghav 34 posts 103 karma points
    Jan 05, 2015 @ 09:30
    Raghav
    0

    Hi,

     

    I am not sure I got this. Since my UmbracoViewPage is strongly typed to custom model , I am not sure how @Model.Content will work since Content is not a property

    in my Model. Besides on trying the same I get the error "Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Content' "

    Regards

    Raghav

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 05, 2015 @ 09:56
    Dennis Aaen
    0

    Hi Raghav

    If you see these cheat sheets http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets there is a cheat sheet for strongly typed Razor, and you will get the current page by @Model.Content in strongly typed Razor. In dynamic Razor the current page is @CurrentPage as you said, I know it says for version 6, but you can also use this in version 7. The
    cheat sheets is an pdf file with a overview of Razor stuff.

    Try to see this documentation too http://our.umbraco.org/documentation/Reference/Mvc/partial-views#StronglytypedPartialViews

    Hope this helps,

    /Dennis


  • 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