Copied to clipboard

Flag this post as spam?

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


  • Lennart Stoop 304 posts 830 karma points
    Jun 22, 2014 @ 13:29
    Lennart Stoop
    0

    SurfaceController routing?

    Hi all,

    I'm working on my first Umbraco 7 project and decided to use a SurfaceController for a simple form which I wanted to wrap in a macro.

    This went pretty smooth until well, requirements changed and I needed to expand the form to also handle edits.

    I decided to stick with the SurfaceController because I wasn't sure if the custom routing/hijacking would still allow my form to be contained within a macro, but it turned out I really can't setup routing for a SurfaceController.

    Eventually I managed with some workarounds (using querystring and urlrewriting) but now I'm wondering which approach I should have taken in the first place. Should I have ditched the SurfaceController and moved to custom routing? How would I wire it up in a macro? Or is there anything else I'm missing?

    Looking forward to hear your experiences :)

  • Jeavon Leopold 2997 posts 13132 karma points MVP 6x admin c-trib
    Jun 23, 2014 @ 21:07
    Jeavon Leopold
    0

    Hi Lennart,

    When you need a SurfaceController for a macro the general approach is to have a SurfaceContoller which returns a Partial View, then have a Partial View Macro which only contains @Html.Action. You can of course pass macro parameters to your controller through the partial view macro.

    Does that make sense?

    Jeavon

  • Lennart Stoop 304 posts 830 karma points
    Jun 24, 2014 @ 09:57
    Lennart Stoop
    0

    Hi Jeavon,

    That is the setup I'm using and it works fine with just one Index action and an HTTP POST (form submit).

    What I don't fully understand is how to handle routing when I add more actions to the surface controller, in my case the Edit action with an identifier, and the HTTP POST after editing.

    Is the routing perhaps to be handled by the template, which passes the identifier using a macro parameter? How would I configure routing in that case? (e.g. /myform/edit/3)

    I may be missing something obvious here, but my main concern is: are surface controllers able to deal with this MVC approach (and routing) within a macro or should I work with a custom MvcRenderController instead (which I'm not sure will work with a macro)?

    Grtz

    L

  • Jeavon Leopold 2997 posts 13132 karma points MVP 6x admin c-trib
    Jun 24, 2014 @ 10:15
    Jeavon Leopold
    1

    Ah ok,

    So SurfaceCOntrollers are auto routed, but they can have child actions which you can either render with a @Html.Action or for a form you can use @using(Html.BeginUmbracoForm("CreateComment", "BlogPostSurface"))

    MvcRenderController is route hijacking so will not work with a Macro.

    Does the above help at all?

    Jeavon

  • Lennart Stoop 304 posts 830 karma points
    Jun 26, 2014 @ 13:00
    Lennart Stoop
    0

    Child actions indeed seem to provide more options using querystring. When I have a moment I'll have a look at the routing mechanism.

    Thanks, Jeavon!

Please Sign in or register to post replies

Write your reply to:

Draft