Question

So I have a HttpPost only ActionResult called Edit. After doing its thing (logic etc), I want it to redirect to a different controller. Lets say the HomeController. Here it is:

[HttpPost]
public ActionResult Edit(Chair chair, string xml)
{
    if (ModelState.IsValid)
    {
        try
        {
            _repository.EditChair(chair, xml);
            return RedirectToRoute(new { contoller = "Home", action = "index"});
        }
        catch (Exception ex)
        {
            //error msg for failed edit in XML file
            ModelState.AddModelError("", "Error editing record. " + ex.Message);
        }
    }
    return View(Chair);

}

Ive tryed other things like return RedirectResult(), RedirectToAction(), RedirectToRoute("string") - but it still keeps returning the index view from the controller the Edit method is in (ChairController).

Whats the right way to do this??

Was it helpful?

Solution 2

Wow wierdest thing ever caused this. The code was correct (as I was sure of to begin with). I tryed to debug it once more, and noticed as I went through the code, that the debugger thingo only marked up some of the code: return RedirectToAction("Index", It actually stopped there, and didnt go through the "Home");. I also noticed that my breakpoint was actually yellow, and was telling me something about the source code was not identical with the original? The what what? It kept saying that through hundreds of saves, restarts, builds and rebuilds. Out of the blue it accepted the code, my breakpoint turned red, the code worked just fine.

Really sorry for waisting your time guys!

OTHER TIPS

Typo:

contoller = "Home"

should be

controller = "Home"

or:

return RedirectToAction("index", "home");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top