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 4693 posts 16769 karma points MVP 2x admin
    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 4693 posts 16769 karma points MVP 2x admin
    Mar 24, 2017 @ 14:32
    Alex Skrypnyk
    0

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

Please Sign in or register to post replies

Write your reply to:

Draft