How to use RedirectToAction to redirect to the default action of different controller?
Posted
by
atbebtg
on Stack Overflow
See other posts from Stack Overflow
or by atbebtg
Published on 2011-03-07T21:36:44Z
Indexed on
2011/03/09
0:10 UTC
Read the original article
Hit count: 138
I am trying to do a RedirectToAction from http://mywebsite/Home/ using the following code:
return RedirectToAction("Index","Profile", new { id = formValues["id"] });
The above code will succesfully take me to
http://mywebsite/Profile/Index/223224
What do I have to do to make it redirect to
http://mywebsite/Profile/223224
Thank you.
I figured out how to do this.
First I have to add custom route rule:
routes.MapRoute("Profile", "Profile/{id}", new { controller = "Profile", action = "Index", id = UrlParameter.Optional });
Then I can do the following:
[AcceptVerbs(HttpVerbs.Post)]
public RedirectResult Index(FormCollection formValues)
{
return Redirect("~/Survey/" + formValues["Id"]);
}
© Stack Overflow or respective owner