Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
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:
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:
if that makes sense ?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted