【问题标题】:RedirectToAction - but I want it to go to http://example.com/controller/action/id?RedirectToAction - 但我希望它转到 http://example.com/controller/action/id?
【发布时间】:2009-07-03 06:53:08
【问题描述】:
【问题讨论】:
标签:
asp.net-mvc
redirecttoaction
【解决方案1】:
似乎配置错误的路由。 Global.asax.cs 中的 RegisterRoutes 方法应如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "Login", id = "" } // Parameter defaults
);
}
在“{controller}/{action}/{id}”行中,{id} 的存在意味着它将被它的值替换。
路由字符串中不存在的任何其他参数都将被解码为 ?some_param=value
【解决方案2】:
啊——因为默认路由需要'id',所以你在视图(html)和控制器中的参数必须叫id。