I have an action as shown below:
[HttpGet] public IActionResult SendEmailVerificationCode(int userId) { SpaceUser user = userManager.FindByIdAsync(userId).Result; bool taskComleted = SendEmailVerificationLink(userId).IsCompleted; if (taskComleted) { AddToErrorData(InfoMessages.EmailVerificationLinkSent_Params, user.Email); return RedirectToAction(nameof(HomeController.Index), "Home"); } else { return RedirectToAction("EmailNotConfirmed", new { userId = user.Id }); } }
When I make the code jump into the else block (when debugging), it redirects to the EmailNotConfirmed action located in the same controller. But it is not redirected to the action of the HomeController Index . Instead, the browser remains on Account/SendEmailVerificationCode and displays a blank page.
HomeController.Index as follows:
[HttpGet] public IActionResult Index() { return View(); }
I tried:
- At the beginning of
SendEmailVerificationCode action was asynchronous, but HomeController.Index not. So I declared them as async. - Then I deleted the
async declaration from both of them. - I tried
return RedirectToAction("Index", "Home"); . SendEmailVerificationCode has an HttpPost attribute; I changed it to HttpGet .
How can I redirect to an action in another controller?
Any help would be appreciated.
PS: I’ve been researching this problem for some time, and I read the solutions for issues such as:
MVC RedirectToAction is not working properly
RedirectToAction is ignored
But none of these questions or questions about the action being redirected after an ajax request helped me.
Thanks.
source share