Copied to clipboard

Flag this post as spam?

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


  • Wayne 10 posts 90 karma points
    Jun 22, 2020 @ 08:38
    Wayne
    0

    Hi all,

    I've a question regarding using the surface controller.

    I've followed this tutorial https://codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/ on how to use a surface controller.

    However if would anyone know how I would call a GET method for the surface controller?

    I can do this fine in regular MVC / .NET however I'm finding it a little difficult to do on Umbraco.

    Thanks,

    Wayne

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jun 22, 2020 @ 12:42
    Ismail Mayat
    0

    Wayne,

    Can you give a bit more context of what you are trying todo? It may that instead of a surfacecontroller you may need route hijacking? See https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers-v7

  • Wayne 10 posts 90 karma points
    Jun 23, 2020 @ 08:14
    Wayne
    0

    Hi Ismail,

    Thank you for your comment.

    What I'm trying to do is creating a template page called manage in Umbraco with two toggle options of type bool.

    When the user selects a bool option inside the manage page, the user clicks save and the page should reload, however when the page reloads the current values of the bool should be retrieved to check if the user has toggled some values already.

    When the user goes to another page, such as "Sales", the sales page should get the bool values from the manage page before the sales page has loaded.

    I was using a Surface Controller to achieve this, but the link you sent looks good to.

    What's the difference between Surface controllers vs hijackings, do you have an example of when I use you a surface controller or hijacking?

    Thanks,

    Wayne

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jun 23, 2020 @ 14:17
    Ismail Mayat
    0

    So looking at your situation I think you need a route hijack, this fires early in the page render, here you can check your property then render with appropriate template.

    So coming back to webforms think of surface controllers and their related partials about like usercontrols. Where you need reusable components.

    Hijacks are more page specific, so lets say you had blog page type and you want to list all comments for that blog page but the comments come from 3rd party system. So in this instance makes more sense to create a hijack of the route then for that page get its comments and add to the extended model for that page and pass it through.

    Regards

    Ismail

  • Wayne 10 posts 90 karma points
    Jun 23, 2020 @ 14:27
    Wayne
    0

    Interesting,

    I've been looking into route hijacking, however for my model e.g

    public class Manager : RenderModel
    {
    
     public Manager(IPublishedContent content) : base(content)
        { }
    
    public bool Toggle1 { get; set; }
    
    public bool Toggle2 { get; set; }
    
    public bool Toggle3 { get; set; }
    

    and my controller method

    public ActionResult SetManagerToggle(RenderModel model)
        {
    
            var model = new RenderModel()
            {
                Toggle1 = model.Toggle1,
                Toggle1 = model.Toggle2,
                Toggle3 = model.Toggle3,
            };
    
            return RedirectToAction("ManagePage", model);
    
        }
    

    As seen in the below image I need to pass in two parameters, would you know how I would implement IPublishedContent and Culture info in my controller?

    Thanks,

    Wayne

    enter image description here

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jun 23, 2020 @ 14:33
    Ismail Mayat
    100

    Take a look at https://github.com/anthonydotnet/ubase its for v8 but there is example of a hijack and also what you have todo to the model etc.

  • Wayne 10 posts 90 karma points
    Jun 23, 2020 @ 14:34
    Wayne
    0

    Excellent, thank you

Please Sign in or register to post replies

Write your reply to:

Draft