Copied to clipboard

Flag this post as spam?

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


  • Ross Ekberg 124 posts 364 karma points
    Sep 20, 2021 @ 16:16
    Ross Ekberg
    0

    Partial View Macro Parameter Issue

    I am trying to retrieve the macro parameter for a partial view.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web.Models
    
    @{
        var catID = Model.GetParameterValue<string>("CatID"); 
        <div>@catID</div>
    }
    

    I have the parameter configured in the macro as "CatID". However, when I drop the macro on a page, and provide a value for the parameter, it always displays as blank.

  • Andrew Z 2 posts 93 karma points
    Sep 20, 2021 @ 20:31
    Andrew Z
    0

    Hmm it seems like the you may want to try "catID" (no leading capitalization) for your parameter name.

    Model.GetParameterValue<string>("catID"); 
    

    It expects the macro parameter alias, which by default I believe get camel-cased when the macro is created, so unless you went and explicitly changed it to use "CatID" I bet it will work with "catID"

  • Ross Ekberg 124 posts 364 karma points
    Sep 28, 2021 @ 13:06
    Ross Ekberg
    100

    The casing probably helped. But really it had to do with the way I was calling the parameter.

    This didn't work:

    Model.GetParameterValue<string>("catID");
    

    But this did:

     Model.MacroParameters["catID"];
    
Please Sign in or register to post replies

Write your reply to:

Draft