Copied to clipboard

Flag this post as spam?

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


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Mar 04, 2016 @ 22:45
    Jesper Ordrup
    0

    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

  • Marc Goodson 2157 posts 14411 karma points MVP 9x c-trib
    Mar 06, 2016 @ 20:28
    Marc Goodson
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft