Render PartialView (UmbracoTemplatePage) from Macro (PartialViewMacroPage)?
Hi,
Im trying to render a partial view from inside a macro.
The macro is registered in the back-office, and has one parameter. The macro is supposed to be available from RTE's.
The macro is based on a partial view, located in ~/Views/MacroPartials, that inherits Umbraco.Web.Macros.PartialViewMacroPage. Tha macro works, and the parameter gets populated as it's supposed.
In the macros partial, i want to render a partial that i'm already using on the site - from various templates. The Partial inherits Umbraco.Web.Mvc.UmbracoTemplatePage and is rendered with @RenderPage() with three arguments on top of the path and model. However, when i'm including the Partial with RenderPage, i get an error message telling me:
The model item passed into the dictionary is of type
'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary
requires a model item of type 'Umbraco.Web.Models.RenderModel'.
I guess that's reasonable, but still, i need to render the Partial from the Macro. How would you approach the problem? Can i change the inheritance in the Partial to make it play nice? What would that be?
I would have your Partial View expect a model of IPublishedContent instead of RenderModel, then it can be easily used from both a view and a Partial View Macro.
e.g.
Partial View:
@inherits UmbracoViewPage<IPublishedContent>
@{
var myHomePage = Model.AncestorOrSelf(1);
}
Render PartialView (UmbracoTemplatePage) from Macro (PartialViewMacroPage)?
Hi,
Im trying to render a partial view from inside a macro.
The macro is registered in the back-office, and has one parameter. The macro is supposed to be available from RTE's.
The macro is based on a partial view, located in ~/Views/MacroPartials, that inherits Umbraco.Web.Macros.PartialViewMacroPage. Tha macro works, and the parameter gets populated as it's supposed.
In the macros partial, i want to render a partial that i'm already using on the site - from various templates. The Partial inherits Umbraco.Web.Mvc.UmbracoTemplatePage and is rendered with @RenderPage() with three arguments on top of the path and model. However, when i'm including the Partial with RenderPage, i get an error message telling me:
I guess that's reasonable, but still, i need to render the Partial from the Macro. How would you approach the problem? Can i change the inheritance in the Partial to make it play nice? What would that be?
Hi Anders,
I would have your Partial View expect a model of IPublishedContent instead of RenderModel, then it can be easily used from both a view and a Partial View Macro.
e.g.
Partial View:
Then it can be called from either View or Macro:
Jeavon
Got it working passing the params with a ViewDataDictionary.
For future reference:
And accessing the params in the partial as follows:
... works from both templates and macro partials.
Thank you for your help!
Perfect!
is working on a reply...