Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 294
BenGC Avatar asked Feb 05 '11 21:02

BenGC


People also ask

How redirect another action method in MVC?

To redirect the user to another action method from the controller action method, we can use RedirectToAction method. Above action method will simply redirect the user to Create action method.

How do I redirect from one action to another controller?

Show activity on this post. I am using asp.net MVC 3 and this works: return Redirect("/{VIEWPATH}/{ACTIONNAME}"); . Example, return Redirect("/account/NotAuthorized"); where 'account' is your view path and your controller name is AccountController. Hope this helps.

How redirect to action in view in MVC?

You can use the RedirectToAction() method, then the action you redirect to can return a View. The easiest way to do this is: return RedirectToAction("Index", model); Then in your Index method, return the view you want.


1 Answers

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"); } 
like image 172
The Scrum Meister Avatar answered Sep 20 '22 18:09

The Scrum Meister