Copied to clipboard

Flag this post as spam?

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


  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 05:07
    Stan
    0

    passing parameters from a webform to a particial view macro

    Hi,

    i recently upgraded a site from v4.5 to the v6.1.6. The creator used mainly webforms for templates. I am currently editing some of the fuctionality via partial views macros. I need to pass parameters to the PVM.

    How do I access the parameters in the macro script?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 12, 2014 @ 08:09
    Dennis Aaen
    0

    Hi Stan,

    If you´re using Razor macro scripts you can get the value of a parameter by using this.

    @Parameter.aliasOfParameter

    And here you find the documentation for this: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-macro-parameters

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 13:01
    Jeavon Leopold
    1

    Hi Stan,

    You access the Macro Parameters like this in a partial view macro:

    var myParam = Model.MacroParameters["myparam"];
    

    This will return a object so you might need to convert it, e.g:

    var myParam = Model.MacroParameters["myparam"].ToString();
    

    Jeavon

  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 14:32
    Stan
    0

    Hi,

    Thanks Guys! Dennis and Jeavon, would i need to include any additional namespaces in my macros? eg:

    @using umbraco.MacroEngines

    thanks again.

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 16:26
    Jeavon Leopold
    100

    Hi Stan,

    No, a very very simple complete partial view macro would only be:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var myParam = Model.MacroParameters["myparam"].ToString();
    }
    <p>@myParam</p>
    

    Jeavon

  • Stan 13 posts 53 karma points
    Mar 12, 2014 @ 16:34
    Stan
    0

    You are a Boss! thanks!

    Usually from docs or forum, there is little info that clearly deals with the partial views macros context, from what i understand is different from razor macros and partial views. I do hope this helps other persons getting started, like me, but have to work with PVMs (partial views macros).

    Cheers!

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 12, 2014 @ 16:48
    Jeavon Leopold
    0

    You're welcome!

    There is some documentation on Partial View Macro's here We do however need some more documentation on UmbracoHelper and IPublishedContent here, I'm sure it will happen soon(ish). Meanwhile I'm sure your questions will get answered on the forum!

    Jeavon

  • Simon 692 posts 1068 karma points
    Jun 03, 2015 @ 08:03
    Simon
    0

    Hi Jeavon,

    Macro parameters, should be added first in the macro settings in the CMS, or you can add a paramter on the fly which is not added to the macro from the CMS?

    Since I would like to pass a dynamic parameter which is the viewbag, to the macro partial view.

    Thank you.

    Kind Regards.

Please Sign in or register to post replies

Write your reply to:

Draft