0

我正在以 Id 作为参数重定向到另一个页面。我通过 using 成功传递了 Id,RedirectToAction但该controller action方法不接受 id 并null始终提供它,即使 url 中有 Id

重定向到该页面的代码

   return RedirectToAction("myaction", new System.Web.Routing.RouteValueDictionary(
                    new { controller = "mycontroller", action = "myaction", Id = 1 }));

网址看起来像这样

  http://localhost:1234/mycontroller/myaction/1

Action看起来像这样

  [HttpGet]
  public ActionResult myaction(int? Id)
  {
      // ID is null here 
  }
4

1 回答 1

1

试试这个

return RedirectToAction("myaction", "mycontroller", new {Id = 1} ); 

或者

return RedirectToAction("myaction", "mycontroller", 
       new System.Web.Routing.RouteValueDictionary( new { Id = 1 }));
于 2013-10-05T17:58:28.183 回答