Copied to clipboard

Flag this post as spam?

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

  • Souvik 4 posts 74 karma points notactivated
    20 days ago

    returning GetCurrentUmbracoPage() inside an ActionMethod from a controller?

    Hello, I have an Action method called IActionResult HandleLogin which is returning GetCurrentUmbracoPage(). But I get this error whenever the method is hit.

    An unhandled exception occurred while processing the request. NullReferenceException: Object reference not set to an instance of an object. Umbraco.Cms.Web.Website.ActionResults.UmbracoPageResult.ExecuteControllerAction(IActionInvoker actionInvoker)

    This return path is only there incase some validations are wrong and the currentpage needs to be refreshed with the validations showing.

    I am new to Umbraco so am I missing anything here? Thank you.

  • Marc Goodson 2005 posts 13175 karma points MVP 8x c-trib
    20 days ago
    Marc Goodson

    Hi Souvik

    You might need to post your controller / action to see exactly where this is going awry but

    is your HandleLogin inside a controller that inherits from SurfaceController?

    If so then there is a specific helper method you can return that will direct the User back to the current Umbraco page but keep Modelstate intact, eg showing all the validation errors! It's called CurrentUmbracoPage() example:

            public IActionResult HandleLogin()
                if (!ModelState.IsValid)
                    return CurrentUmbracoPage();
    // if all is valid - do some stuff - eg send an email, update database etc
                return RedirectToCurrentUmbracoPage();

    The 'RedirectToCurrentUmbracoPage takes the user to the current page but wipes the modelstate, so it's likely if you are on a special login page that you don't want to return to the login page but instead redirect somewhere else...

    In which case you can use the other RedirectTo helpers listed here:

    to go to a specific page etc



  • Souvik 4 posts 74 karma points notactivated
    1 week ago

    Hi Marc, Thanks for the reply. I fixed the issue. I was making the mistake of passing all the parameters of the Surface controller inside the constructor as private readonly which gave me an error whenever I tried to call the CurrentUmbracoPage().

Please Sign in or register to post replies

Write your reply to: