我使用下面的代码试图从http://mywebsite/Home/做一个RedirectToAction:如何使用RedirectToAction重定向到其他控制器的默认动作?
return RedirectToAction("Index","Profile", new { id = formValues["id"] });
上面的代码将成功地把我带到
http://mywebsite/Profile/Index/223224
我有什么做的,使重定向到
http://mywebsite/Profile/223224
谢谢您。
我想出了如何做到这一点。
首先我必须添加自定义的路由规则:
routes.MapRoute("Profile", "Profile/{id}", new { controller = "Profile", action = "Index", id = UrlParameter.Optional });
然后,我可以做到以下几点:
[AcceptVerbs(HttpVerbs.Post)]
public RedirectResult Index(FormCollection formValues)
{
return Redirect("~/Survey/" + formValues["Id"]);
}
你能告诉我们你的路线定义吗? – frennky 2011-03-07 21:44:39
我从来没有手动定义过一个,所以我假设我正在使用默认路由定义。 – atbebtg 2011-03-07 21:48:47