Copied to clipboard

Flag this post as spam?

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


  • Paul Stoker 39 posts 72 karma points c-trib
    Feb 04, 2014 @ 15:59
    Paul Stoker
    0

    Umbraco 6.1.6 - Access Macro Parameters within a Surface Controller

     

    Hi, I'm converting some older web forms style macros to the MVC style and I'm trying to find a way of accessing macro paramters within a Surface Controller.

    Originally I had this:

     

    • Macro - 5 x Parameters
    • User Control / Code behind - 5 x Public Properties (for macro parameters)
    Now I have:
    • Macro - 5 x Parameters
    • Macro Partial View
    • View for a Form with Stronlgy Typed Model
    • Surface Controller
    My main question is, how can I access macro parameters in the controller?
    If this process looks flawed or there is a better way, let me know.
    Thank you

     

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 11, 2015 @ 00:34
    Marc Goodson
    0

    Hi Paul

    You can get access to your macro parameters in your MacroPartial

    (because the model inherits from Umbraco.Web.Macros.PartialViewMacroPage)

    using:

    var myParam = Model.GetParameterValue<string>("alias","defaultValue");
    

    You can pass these to a Surface controller action by using additional data in RouteValues eg:

    Html.Action("ActionName","ControllerName", new { id = myParam })
    

    or in your BeginUmbracoForm

    @using (Html.BeginUmbracoForm<ControllerNameController>("ActionName",new {id=myParam}))
    

    or as a 'hidden field' on the model you pass to the Partial View:

    @{ var myPartialModel = new MyPartialModel();
    myPartialModel.MyParam = myParam;
    Html.RenderPartial("MyPartialView", myPartialModel); }
    

    But the surface controller inself is not aware of the Macro, and it's parameters if that makes sense?

    regards Marc

Please Sign in or register to post replies

Write your reply to:

Draft