How to use RedirectToAction to redirect to the default action of different controller?
- by atbebtg
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"]);
}