Reputation: 229
i want to redirect to another action in same controller. how can we achieve this? i tried like return
RedirectToAction("NotAuthorized");
Upvotes: 11
Views: 27815
Reputation: 9
try to explore the ControllerBase first, or go to the definition of the Controller which is what your controller inherits and then look for 'redirect'
Upvotes: 0
Reputation: 102368
return RedirectToAction("ActionName");
Instead of return Redirect("/Elearning/NotAuthorized");
do this:
return RedirectToAction("NotAuthorized"); // if you're inside the Elearning controller
or
RedirectToAction("NotAuthorized", "Elearning"); // if calling from other controller
Upvotes: 20
Reputation: 173
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.
Upvotes: -1
Reputation: 69953
If you want to return a redirect
return RedirectToAction("NotAuthorized");
is the valid way to do this. Make sure that your method actually exists.
Alternatively, if you don't want a redirect
return View("NotAuthorized");
works as well.
Upvotes: 2