我正在重定向到另一个页面,其中Id为参数。我使用RedirectToAction
成功传递了ID,但controller action
方法不接受ID,并且即使在网址中存在Id时也始终为null
提供
重定向到该页面的代码
return RedirectToAction("myaction", new System.Web.Routing.RouteValueDictionary(
new { controller = "mycontroller", action = "myaction", Id = 1 }));
Url看起来像这样
http://localhost:1234/mycontroller/myaction/1
Action
看起来像这个
[HttpGet]
public ActionResult myaction(int? Id)
{
// ID is null here
}
答案 0 :(得分:1)
尝试一次
return RedirectToAction("myaction", "mycontroller", new {Id = 1} );
或
return RedirectToAction("myaction", "mycontroller",
new System.Web.Routing.RouteValueDictionary( new { Id = 1 }));