Copied to clipboard

Flag this post as spam?

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


  • Hannes 28 posts 189 karma points
    Jan 06, 2023 @ 22:05
    Hannes
    0

    Umbraco 10 - Surface controllers - Multiple handlers per page

    Hi there,

    is it possible / is it going to be possible to support multiple handlers per page in Surface controllers for Umbraco version >= 10? I have a form with 2 submit buttons (Save, Delete) and would expect for this simple workflow to be supported.

    Its supported in .Net Core out of the box so I would hope Umbraco supports this also.

    Anybody from the Umbraco community or from HQ have any thoughts?

    Thanks a lot.

    Hannes

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 07, 2023 @ 08:57
    Huw Reddick
    0

    Hi Hannes,

    As far as I can tell this should work fine, I just did a quick test and it appears to work.

    Example. Form

        @using (Html.BeginUmbracoForm<TagCloudSurfaceController>("DoWorkOne",  FormMethod.Post))
        {
            <button asp-action="DoWorkOne" asp-controller="TagCloudSurface" type="submit">log in</button>
            <button asp-action="DoWorkTwo" asp-controller="TagCloudSurface" type="submit">sign up</button>
    
        }
    

    It called the correct actions when bttons were clicked

  • Hannes 28 posts 189 karma points
    Jan 07, 2023 @ 19:07
    Hannes
    0

    Hi Huw,

    Thanks for looking into this for me. Much appreciated. Unfortunately I cannot confirm this. Its still not working for me. Based on your example, DoWorkOne is always called.

    Here is my test implementation based on your code snippet. Maybe you can take a look and point out where the issue might be? Thanks!

    Add view component to page view:

    @await Component.InvokeAsync("TagCloud")
    

    ViewComponent class:

    namespace App.Core.ViewComponents
    {
        public class TagCloudViewComponent : ViewComponent
        {
            public TagCloudViewComponent()
            {            
            }
    
            public IViewComponentResult Invoke()
            {
                var tagCloudModel = new TagCloudModel
                {                
                };
    
                return View(tagCloudModel);
            }
        }
    }
    

    SurfaceController class:

    namespace App.Core.Controllers
    {
        public class TagCloudSurfaceController : SurfaceController
        {
            public TagCloudSurfaceController(
                IUmbracoContextAccessor umbracoContextAccessor,
                IUmbracoDatabaseFactory databaseFactory,
                ServiceContext services,
                AppCaches appCaches,
                IProfilingLogger profilingLogger,
                IPublishedUrlProvider publishedUrlProvider
                )
                : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
            {
    
            }
    
            [HttpPost]
            public IActionResult DoWorkOne(TagCloudModel model)
            {
                return CurrentUmbracoPage();
            }
    
            [HttpPost]
            public IActionResult DoWorkTwo(TagCloudModel model)
            {
                return CurrentUmbracoPage();
            }
        }
    }
    

    View component partial:

    @using App.Core.Controllers;
    @using (Html.BeginUmbracoForm<TagCloudSurfaceController>("DoWorkOne", FormMethod.Post))
    {
        <button asp-action="DoWorkOne" asp-controller="TagCloudSurface" type="submit">log in</button>
        <button asp-action="DoWorkTwo" asp-controller="TagCloudSurface" type="submit">sign up</button>
    }
    
  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 07, 2023 @ 20:35
    Huw Reddick
    0

    what version of Umbraco are you testing on? It works fine for me (using 10.4.0-rc) each action gets called by the relevant submit button.

  • Hannes 28 posts 189 karma points
    Jan 07, 2023 @ 20:58
    Hannes
    0

    Thanks for letting me know. I guess that could be it. I'm on 10.3.2. Though I'm not seeing that particular change in the release notes for 10.4.0. Could you give it a try for 10.3.2? Thanks!

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 07, 2023 @ 21:00
    Huw Reddick
    0

    I think I have a 10.3.2 test site so will give it a try if I still have it

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Jan 07, 2023 @ 21:22
    Huw Reddick
    100

    OK, I can definitely confirm it doesn't work in 10.3.2 but does in 10.4.0-rc

  • Hannes 28 posts 189 karma points
    Jan 07, 2023 @ 21:35
    Hannes
    0

    That's great to know and very helpful. Thanks Huw. I'll upgrade to 10.4.0 as soon as its out. Your help has been much appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft