I want to render @{Html.RenderPartial("MailSection");} inside my PartialViewMacroPage how can I do that I try by writing
@{Html.RenderPartial("MailSection");}
but its not working for me. it gives error like
Error loading Partial View script (file: ~/Views/MacroPartials/ParutionsList.cshtml)
In MVC when you use Html.RenderPartial("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 the current model is of type PartialViewMacroPage, so unless your Partial view is also based on this model you will get an error.
Usually the workaround is to make the partial you want to render, inherit from IPublishedContent eg change the @inherits statement at the top of the partial to be:
@inherits UmbracoViewPage<IPublishedContent>
You would then use inside the partial:
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:
How to render partial view in side Macro view
Hello,
I want to render @{Html.RenderPartial("MailSection");} inside my PartialViewMacroPage how can I do that I try by writing @{Html.RenderPartial("MailSection");}
but its not working for me. it gives error like Error loading Partial View script (file: ~/Views/MacroPartials/ParutionsList.cshtml)
can any one help me in this.?
Thanks, Kevin.
Hi Kevin
In MVC when you use Html.RenderPartial("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 the current model is of type PartialViewMacroPage, so unless your Partial view is also based on this model you will get an error.
Usually the workaround is to make the partial you want to render, inherit from IPublishedContent eg change the @inherits statement at the top of the partial to be:
You would then use inside the partial:
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("MailSection", Model.Content);}
if that makes sense ?
regards
Marc
Not sure if this helps anyone, but I managed to get a partial to render in macro after lots of trial and error.
Macro
@{ Layout = null; } @{ Html.RenderAction("ActionName", "ControllerName"); }
Controller
Any controller logic here
return PartialView("YourPartialName", viewModel);
Partial View
@{ Layout = null; }
Model Logic Here
is working on a reply...