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.
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").
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' "
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.
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
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
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
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
is working on a reply...