Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • kevin 1 post 21 karma points
    Feb 16, 2016 @ 18:36
    kevin
    0

    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.

  • Marc Goodson 2148 posts 14352 karma points MVP 8x c-trib
    Feb 27, 2016 @ 00:59
    Marc Goodson
    0

    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:

    @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:

    @{Html.RenderPartial("MailSection", Model.Content);}

    if that makes sense ?

    regards

    Marc

  • Robert Tunna 2 posts 22 karma points
    Mar 15, 2017 @ 15:23
    Robert Tunna
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft