BenGC
BenGC

Reputation: 2854

ASP.NET MVC 3 - redirect to another action

I want to redirect the Index action of the Home controller to another controller's action and nothing else. My code is thus:

    public void Index()
    {
        //All we want to do is redirect to the class selection page
        RedirectToAction("SelectClasses", "Registration");
    }

Right now, this just loads a 0 kB blank page and does nothing. I have a feeling it has something to do with that void return type, but I don't know what else to change it to. What's the issue here?

Upvotes: 73

Views: 123248

Answers (5)

Siby Sunny
Siby Sunny

Reputation: 742

return RedirectToAction("ActionName", "ControllerName");

Upvotes: 1

Soheil Soheili
Soheil Soheili

Reputation: 111

You have to write this code instead of return View(); :

return RedirectToAction("ActionName", "ControllerName");

Upvotes: 11

The Scrum Meister
The Scrum Meister

Reputation: 30111

Your method needs to return a ActionResult type:

public ActionResult Index()
{
    //All we want to do is redirect to the class selection page
    return RedirectToAction("SelectClasses", "Registration");
}

Upvotes: 152

indiPy
indiPy

Reputation: 8062

Should Return ActionResult, instead of Void

Upvotes: 15

Femaref
Femaref

Reputation: 61427

You will need to return the result of RedirectToAction.

Upvotes: 20

Related Questions