Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Jul 12, 2017 @ 07:55
    Bex
    0

    U7 PartialView/Macro server side functionality

    Hi

    I understand this is probably the most basic of basic questions but I really need pointing in the right direction!

    I have spent the last 6 years working on U 4 - 6 with c#, macros and xslt and standard webforms. I have now been handed an Umbraco 7 project and although I have dabbled in tiny bits of Umbraco 7 I have never created anything equivalent to a usercontrol macro.

    I want to do what seems like the simplest thing.. The "usercontrol" loads, checks a few things server side and depending what it finds presents the user with some different options in the form of buttons or a drop down list, and when they click one it does some more server side stuff and stores a cookie.

    So far I've got all the checking serverside stuff directly in a partialview/cshtml file and showing some buttons but I can't work out the click events of the buttons.. I think I need a controller with actions but I don't understand how I link it all together.

    Is there a really simple tutorial somewhere on this? I have found this: https://our.umbraco.org/documentation/Reference/Routing/surface-controllers

    and

    https://our.umbraco.org/documentation/Implementation/Default-Routing/Controller-Selection/

    but it's such a different way of working I'm totally confused and don't really understand where to start!

    Thanks for any help

    Bex

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 12, 2017 @ 08:58
    Damiaan
    0

    Hi Bex,

    If you want to do this serverside you have found the right way. Surfacecontrollers are the way to go. Yet, can be hard to understand at the beginning. If it is to extend the umbraco backend, then other ways have emerged, the mantra became: think AngularJS and API calls.

    I would suggest you start with a "dirty" way of figuring out what this MVC exactly does.

    Let say, take a form

    <form action="post">
      <input type="text" name="fieldname" /> <input type="submit" value="send" />
    </form>
    

    you could on the same (partial) view add some simple code to interact with this:

    if (IsPost)
    {
        @Request.Form["fieldname"]
    }
    

    If you put this into a partial you have replaced your usercontrol for 90%... I will get death threats from showing you such a horrible way. Entering the world of MVC. Split the Controller (c# code) from the View (Razor template). And that is the reason of existence for Surface Controllers.

    To answer your question very short... Try this tutorial from the getting started section in the documentation: creating forms

    Kind regards
    Damiaan

Please Sign in or register to post replies

Write your reply to:

Draft