dinesh
dinesh

Reputation: 229

how to redirect to another action in same controller?

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

Answers (5)

Rosario Capuno
Rosario Capuno

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

Leniel Maccaferri
Leniel Maccaferri

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

user864675
user864675

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

Brandon
Brandon

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

itsmatt
itsmatt

Reputation: 31406

Try

return RedirectToAction("SomeAction");

Upvotes: 1

Related Questions