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?
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.
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.
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.
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"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With