RedirectToAction not changing URL or navigating to Index view

后端 未结 8 867
长情又很酷
长情又很酷 2020-12-01 07:49

I tried using a RedirectToAction after I have done a post to the controller and saved but the URL does not change and the redirect does not seem to work. I need

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 08:18

    I decided to write this comment as a new answer because I think it needs more description and may someone can't see it in comments if has my problem. So I Apologize if you think this is not an answer and must be written in the comment section.

    In some cases, I used RedirectToAction to send the user to another action if input values are incorrect or insufficient and avoid continuing the current process as below:

    if (inputValues == null)
    {
      RedirectToAction("index");
    }
    

    That keeps not working and continues the current process to take unhandled error. I search and read some articles but I can't find a solution. Calling of RedirectToAction is not from Ajax code and routing is so simple without any parameters even. So why is not working? Finally, I found the simple mistake I did: Forgot to put "return" keyword before RedirectToAction. I changed the code as below:

    if (inputValues == null)
    {
      return RedirectToAction("index");
    }
    

    And that is worked. Hope this help.

提交回复
热议问题