Copied to clipboard

Flag this post as spam?

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


  • Davy Meybos 11 posts 96 karma points
    Mar 23, 2017 @ 08:04
    Davy Meybos
    0

    RenderMvcController async ActionResult vs Surfacecontroller CurrentUmbracoPage

    Hi all,

    I'm struggling to get the SurfaceController CurrentUmbracoPage actionresult to work with async actions on my RenderMvcController.

    Basically, i've created a custom controller, hijacking the Umbraco Routes:

    public class HomeController : Umbraco.Web.Mvc.RenderMvcController
    {
        public async Task<ActionResult> Home(RenderModel model)
        {
            // I've skipped the async stuff
            return CurrentTemplate(model);
        }
    }
    

    I also have a form post on my homepage which posts to a SurfaceController:

    public class LoginController : Umbraco.Web.Mvc.SurfaceController
    {
        public async Task<ActionResult> Login(string email, string pw)
        {
            return CurrentUmbracoPage();
        }
    }
    

    return CurrentUmbracoPage() causes a ysod: The asynchronous action method 'Home' returns a Task, which cannot be executed synchronously.

    Can anybody explain what I am missing here?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 24, 2017 @ 14:27
    Alex Skrypnyk
    0

    Hi Davy

    I think it's not possible to do.

    You can wrap async operations in sync, but I think it's not possible to make SurfaceController or RenderMvcController to return Task.

    Thanks,

    Alex

  • Davy Meybos 11 posts 96 karma points
    Mar 24, 2017 @ 14:31
    Davy Meybos
    100

    Hi Alex,

    thanks for the reply. I'm really sure it's possible to work with async Tasks in a SurfaceController or RenderMvcController.

    It is the combination with CurrentUmbracoPage() that is causing the problem.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 24, 2017 @ 14:32
    Alex Skrypnyk
    0

    Yes, I think so too. Will edit an answer.

  • Arnaud Bertrand 6 posts 76 karma points
    Oct 02, 2019 @ 06:43
    Arnaud Bertrand
    0

    This still seems to be an issue but I think I found a workaround: instead of returning CurrentUmbracoPage() return Redirect(Request.UrlReferrer.ToString()). That seems to be working

  • Martin Rhodes 13 posts 130 karma points
    Mar 31, 2020 @ 20:25
    Martin Rhodes
    1

    The above will lose ModelState, and incidentally can be simplified using return RedirectToCurrentUmbracoPage().

    What you can do though is a good old fashioned MVC return View("viewName", yourContentModel), keeping in mind that CurrentPage represents the IPublishedContent of the current page.

Please Sign in or register to post replies

Write your reply to:

Draft