Copied to clipboard

Flag this post as spam?

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


  • Tom 161 posts 322 karma points
    Dec 03, 2016 @ 11:20
    Tom
    0

    How to Access Macro Parameter with C# server side code

    I am on Umbraco 7.4.2 and I have built a macro for my users with a single parameter. Now the partial has a Kendo Grid on it and what I want to do to build the grid with data based on the macro parameter that the users select. I know how to access the parameter with razor but I want to access the parameter from my C# server side controller.

    If you can help, please advise.

    Thanks

    Tom

  • Jeremy Newman 18 posts 190 karma points
    Dec 04, 2016 @ 00:51
    Jeremy Newman
    1

    You can pass the Macro Parameter from your MacroPartial to the controller method as a Parameter.

    View:

    @{
        var args = new
        {
            myParam = Model.MacroParameters["myParam"]
        };
    }
    
    @Html.Action("MyMethod", "MyController", args)
    

    Controller Method:

    public ActionResult MyMethod(int myParam)
    

    If your controller is in a plugin then you will need to include the area in your args on the view as well...

    @{
        var args = new
        {
            area = "MyArea",
            myParam = Model.MacroParameters["myParam"]
        };
    }
    
    @Html.Action("MyMethod", "MyController", args)
    
Please Sign in or register to post replies

Write your reply to:

Draft