RedirectToAction not changing URL or navigating to Index view

后端 未结 8 857
长情又很酷
长情又很酷 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:20

    This is a bit late.... but I had the same problem in MVC5. I had 2 actions with the same name, which is common enough. I wasn't getting any errors that I could capture in Application_Error or OnException in the controller. I tried adding in the action, controller, area in the RedirectToAction route variable to no avail. I ended up renaming the POST action to EditPost and everything works now for me. Hope this helps.

    public ActionResult Edit(int id)
    {
        return View();
    }
    
    [HttpPost, ValidateAntiForgeryToken]
    public ActionResult Edit(MyInputModel myInputModel)
    {
        return View();
    }
    
    public ActionResult Create()
    {
        return RedirectToAction("Edit", new {id = 1});
    }
    

提交回复
热议问题