【问题标题】:mvc RedirectToAction passing a parameter [duplicate]传递参数的mvc RedirectToAction [重复]
【发布时间】:2011-09-19 08:35:37
【问题描述】:

可能重复:
RedirectToAction with parameter

我在控制器主页中,在 ActionResult Id 中,其中包含从方法返回的字符串名称 get 列表。我想使用该列表 RedirectToAction (Id2)。在 View -> Id2 中,该列表名称 get 的 ViewData 为空,不包含填充的 Itemsn 的列表。如何从 actionResult 重定向到另一个 actionresult 传递参数的另一个视图?

【问题讨论】:

    标签: asp.net-mvc-2 query-string redirecttoaction


    【解决方案1】:

    这样使用

    如果有多个参数则:

    return RedirectToAction("actionname", new { id = "id", name="name" }); // change parameters according to requirement
    

    如果你只有 id 作为参数,那么:

    return RedirectToAction("actionname", new { id = "id" });
    

    【讨论】:

      【解决方案2】:
      RedirectToAction( new RouteValueDictionary( 
           new{ 
                controller = "mycontroller", 
                action = "myaction", 
                id = "MyId" 
           } 
      ));
      

      【讨论】:

        猜你喜欢
        • 2010-10-18
        • 1970-01-01
        • 2011-09-06
        • 2010-10-14
        • 1970-01-01
        • 2021-10-05
        • 1970-01-01
        • 2011-09-25
        • 1970-01-01
        相关资源
        最近更新 更多