【发布时间】:2015-03-07 10:09:10
【问题描述】:
当我尝试重定向到操作时,收到的参数始终为空?我不知道为什么会这样。
ActionResult action1() {
if(ModelState.IsValid) {
// Here user object with updated data
redirectToAction("action2", new{ user = user });
}
return view(Model);
}
ActionResult action2(User user) {
// user object here always null when control comes to action 2
return view(user);
}
对此我还有一个疑问。当我使用路由访问操作时,我只能通过RouteData.Values["Id"] 获取值。路由的值不会发送到参数。
<a href="@Url.RouteUrl("RouteToAction", new { Id = "454" }> </a>
我想念任何配置吗?或任何我想念的东西。
ActionResult tempAction(Id) {
// Here Id always null or empty..
// I can get data only by RouteData.Values["Id"]
}
【问题讨论】:
-
有时由于以下原因可能会发生这种情况。我们的自定义路由必须放在下面的默认路由之前才能正确识别。 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "controller ", action = "action ", id = UrlParameter.Optional } );
标签: asp.net-mvc-4