redirect to a actionresult in mvc but not want to go to page by return view()

33,638

You could redirect:

return RedirectToAction("index");

and if the action is on a different controller specify the controller name as well:

return RedirectToAction("index", "home");
Share:
33,638
Admin
Author by

Admin

Updated on July 07, 2020

Comments

  • Admin
    Admin almost 4 years

    i want a facility that if user login then goes to home/index

    i not want to use

    return view('~/views/home/index');
    

    i want to redirect it to a actionresult index of home controller of my web-application(in asp.net mvc)

    how i can do this without return view(); i want to redirect him.

    public actionresult login
    
    if(userlogin)
    {
    // goes to index page ? what i do here then user goes to index page of home controller
    }
    else
    {
    return view()
    }
    
  • Admin
    Admin almost 14 years
    i used return Redirect("/home/index");
  • Darin Dimitrov
    Darin Dimitrov almost 14 years
    That's not good as you are hardcoding the route /home/index and the day you modify your route rules it will bite you.
  • GalacticCowboy
    GalacticCowboy almost 14 years
    Plus, return Redirect("/home/index"); fails as soon as you're running in a vroot. At least preface it with a "~", though doing the RedirectToAction(), as Darin pointed out, is much better.