Do you mean inside a Macro Partial View ? - Render a separate partial using Html.Partial or Html.RenderPartial etc ?
if so then yes you can.
In MVC when you use Html.Partial("viewname") the model that is passed to the partial view is the 'current model' of the view you are calling it from.
Since you are inside a Macro Partial the current model is of type PartialViewMacroPage, so unless your Partial view is also based on this model you will get an error.
The trick is to make the partial you want to render, inherit from IPublishedContent eg change the @inherits statement at the top of the partial (not the macro partial) to be:
@inherits UmbracoViewPage
Model.GetPropertyValue("aliasName") rather than Model.Content.GetPropertyValue("aliasName") etc/
with this change made then inside the Macro you can render the partial view by passing the IPublishedContent element of the PartialViewMacroPage class like so:
Html.Partial in macroscript?
Hi all,
We have some macroscripts that runs and we cant change them to regular partials as they are part of a package.
Is it possible in some way to use Html.Partial from a macroscript? It doesnt seem to be available.
I want to render som partials and use the output in the macroscript.
/Jesper
Hi Jesper
Do you mean inside a Macro Partial View ? - Render a separate partial using Html.Partial or Html.RenderPartial etc ?
if so then yes you can.
In MVC when you use Html.Partial("viewname") the model that is passed to the partial view is the 'current model' of the view you are calling it from.
Since you are inside a Macro Partial the current model is of type PartialViewMacroPage, so unless your Partial view is also based on this model you will get an error.
The trick is to make the partial you want to render, inherit from IPublishedContent eg change the @inherits statement at the top of the partial (not the macro partial) to be:
@inherits UmbracoViewPage
Model.GetPropertyValue("aliasName") rather than Model.Content.GetPropertyValue("aliasName") etc/
with this change made then inside the Macro you can render the partial view by passing the IPublishedContent element of the PartialViewMacroPage class like so:
@{Html.RenderPartial("MyLovelyPartial", Model.Content);}
or
@Html.Partial("MyLovelyPartial",Model.Content)
if that makes sense ?
regards
Marc
is working on a reply...