Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core RedirectToAction doesn't exit function?

I have the following snippet

        if (hasRegistrations)
        {
            RedirectToAction("Manage");
        }

        return View();

Even thought RedirectToAction is executed, the execution still flows to return View();

How should this be handled correctly?

like image 675
Jack Shepherd Avatar asked Dec 12 '25 06:12

Jack Shepherd


1 Answers

You need to return RedirectToAction("Manage");

Explanation:

The RedirectToAction method returns RedirectToRouteResult rather than immediately returning a HTTP redirect response. So you have to return the RedirectToRouteResult from the controller action. In your example execution is continuing and return View() is being run instead.

like image 197
Tom Robinson Avatar answered Dec 14 '25 19:12

Tom Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!