Copied to clipboard

Flag this post as spam?

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

  • Troels Larsen 75 posts 280 karma points
    Nov 08, 2011 @ 14:45
    Troels Larsen

    Razor and Macro Container

    Hey ppl 

    I am trying to get the macro container to work inside a razor macro but all i get is a string container the old macro tag "<umbraco:macro..... " and i cant seem to find a helper method for rendering the output of that macro. IS it even poseble to do with the current support for razor ? Or do i need to make a helper method that renders the "old macro" and the returns the rendered html ? 

    any ideas ? 


  • Barry Fogarty 493 posts 1129 karma points
    Nov 09, 2011 @ 11:29
    Barry Fogarty

    If the macro you are trying to use in the container is razor, you can try

    @RenderPage("filename.cshtml", arrParams)

    arrParams is an optional parameter to allow you to pass data into the razor macro.

    There is some more info in the wiki:

    I also found this page useful for learning about ways to structure razor code.

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Dec 03, 2012 @ 16:41


    until now i still have not found a (the?) way to render a macro container using razor.  This is the only thing I still use XSLT for.

    How did you solved your issue?

    Kind regards

  • Troels Larsen 75 posts 280 karma points
    Dec 03, 2012 @ 16:59
    Troels Larsen

    Hey Damiaan 

    if u are using razor and master pages (4.7 way) i used <umbraco:Item field="macroContainer"  /> 

    if u are 4.10 + and use mvc u can use the @Umbraco.Field()


  • wolulcmit 357 posts 693 karma points
    Dec 10, 2013 @ 08:52

    @Umbraco.Field("youfieldhere") works for me but as soon as I put anything in my macro that's dynamic I get the error "Error loading Partial View script"
    What do I need to put in my Partial to get it to inherit from the right View?

    if I render my partial directly it works.
    @if (Model.Content.HasValue("macroPicker", true)){
            @Umbraco.Field("macroPicker") // doesnt work if partial contains anything dynamic
            @Html.Partial("my-partial-name") // works

    what to do to get this to work or get a decent error message?

  • wolulcmit 357 posts 693 karma points
    Dec 10, 2013 @ 09:12

    I got it working with the following horrible hack

    @if (Model.Content.HasValue("macroPicker", true)){
            var partialName = Umbraco.Field("macroPicker").ToString();
            var trimmedPartialName = partialName.Substring(63, partialName.Length - 71); // trimming the string to get just the macro name

    How's it meant to be done properly?

  • wolulcmit 357 posts 693 karma points
    Dec 10, 2013 @ 09:20

    Ah, ok aswering my own question here
    put the following in you macro partial at the top

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    rather than the usual @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

  • Tom 119 posts 447 karma points
    Feb 28, 2014 @ 08:22

    @wolulcmit - did you ever find a proper way?

  • Roman (rc21) 7 posts 72 karma points
    Oct 01, 2014 @ 17:49
    Roman (rc21)

    @Html.Raw( Model.Content.GetPropertyValue("macroPicker") )

Please Sign in or register to post replies

Write your reply to: