Copied to clipboard

Flag this post as spam?

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


  • TempleClause 32 posts 248 karma points
    Feb 12, 2015 @ 22:56
    TempleClause
    1

    Render a Macro Partial View in a Partial View

    Hello, I try to render a Macro Partial View from within a Partial View like so:

    @{ Html.RenderPartial("~/Views/MacroPartials/Divider.cshtml"); }
    

    But it doesn't work.. gives me this error message:

    enter image description here

    When this works I would also like to pass Parameters from the PartialView to the Macro. Let's say I would want to pass @CurrentPage.images to the macro parameter called "images". Which I would then get in the Macro with Model.MacroParameters["images"]

    Thanks for helping!

    EDIT: this is my umbraco version: Umbraco version 7.2.1 assembly: 1.0.5462.37503

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 12, 2015 @ 23:08
    Dennis Aaen
    1

    Hi TempleClause,

    I think you should called the partial view like this

    @{Html.RenderPartial("Divider");}

    Try to see this documentation https://our.umbraco.org/documentation/Reference/Mvc/partial-views

    You said that you are passing a parameter to the parial view, then I think you are working with a parial view maraco. For call this you need to do it like this.

    @Umbraco.RenderMacro("Divider")

    The documentation for the parial view macros can you find here: https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/

    Hope this helps,

    /Dennis

  • TempleClause 32 posts 248 karma points
    Feb 12, 2015 @ 23:34
    TempleClause
    102

    Yes exactly, was looking for @Umbraco.RenderMacro("Divider")

    Just need to be able to pass the parameters. I see this definition:

    public IHtmlString RenderMacro(string alias, IDictionary<string, object> parameters);
    

    So i did this:

    @{
        Dictionary<string, object> asd = new Dictionary<string, object>();
        asd.Add("test", "cool this works!");
    }
    @Umbraco.RenderMacro("Divider", asd)
    

    And tried to read the "test" parameter like this:

    @Model.MacroParameters["test"]

    but now it get the error message: Error loading Partial View script (file: ~/Views/MacroPartials/Divider.cshtml)

    By the way, is there a way to turn on error messsages? So I would see why this Partial View gets an error?

    Thanks for the help

    EDIT: solution is in next post

  • TempleClause 32 posts 248 karma points
    Feb 12, 2015 @ 23:39
    TempleClause
    0

    Figured it out myself! I forgot to define the parameter in the Umbraco Backend under Devolper/Macros

    Thanks for helping. Looks like you really are the friendliest community ;-)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 12, 2015 @ 23:51
    Dennis Aaen
    0

    Hi TempleClause,

    Yes we are a friendly community with some nice people that are trying to help each other : -). Happy to hear that you solve this. - Remember to mark the topic as solved so others can go straight to the solution if they come across the same issue. You do this by clicking the little green tick on the post that give you the solution to your question / problem.

    Happy Umbraco coding.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft