(I also verified it appears on the developer section of the back office)
In my partial view code (Partial View Macro Files), I tried to change as follow, from:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
string myWebsiteMagazineCategories = CurrentPage.myWebsiteMagazineCategory; //get the checked item from the checkbox list
To:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
string myWebsiteMagazineCategories = Model.Content.myWebsiteMagazineCategory; //get the checked item from the checkbox list
And from:
var magazine_node = Umbraco.Content(MagazineID);
To:
var magazine_node = Umbraco.TypedContent(MagazineID);
But now I get the following error:
Compiler Error Message: CS1061: 'IPublishedContent' does not contain a definition for 'myWebsiteMagazineCategory' and no extension method 'myWebsiteMagazineCategory' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
In a Partial View Macro then the underlying model is of type PartialViewMacroModel
A Macro can be placed on any page
So it won't be specifically 'typed' to a specific type of Modelsbuilder generated Model, as these match to DocumentTypes.
Model.Content does represent a strongly typed IPublishedContent object representing the CurrentPage the macro is on, but without strongly typed access to properties:
If you knew for sure your macro was only ever on a NewsArticle page then you could cast the Model.Content item to that particular generated modelsbuilder type eg
var currentNewsArticle = Model.Content.As<NewsArticle>();
and then you would have access to the strongly type properties generated by modelsbuilder and be able to access them via
Getting errors while try to convert code from dynamic to strongly typed
Hi, I try to convert my code from dynamic to strongly typed. I'm using V7 and in my web.config I have:
(I also verified it appears on the developer section of the back office)
In my partial view code (Partial View Macro Files), I tried to change as follow, from:
To:
And from:
To:
But now I get the following error:
Any idea?
Thanks a lot !
HI Meni
In a Partial View Macro then the underlying model is of type PartialViewMacroModel
A Macro can be placed on any page
So it won't be specifically 'typed' to a specific type of Modelsbuilder generated Model, as these match to DocumentTypes.
Model.Content does represent a strongly typed IPublishedContent object representing the CurrentPage the macro is on, but without strongly typed access to properties:
So you can access properties generically via:
If you knew for sure your macro was only ever on a NewsArticle page then you could cast the Model.Content item to that particular generated modelsbuilder type eg
and then you would have access to the strongly type properties generated by modelsbuilder and be able to access them via
if that helps!
regards
Marc
is working on a reply...