mvc RedirectToAction 传递参数

发布于 2024-12-05 04:35:45 字数 417 浏览 6 评论 0原文

可能的重复:
带参数的RedirectToAction

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

Possible Duplicate:
RedirectToAction with parameter

I am in controller home, in ActionResult Id which has a list of string name get returned from a method. I want to RedirectToAction (Id2) using that list. In View -> Id2 the ViewData of that list name get is null, doesn;t contain the list of the Itemsn populated. How can I redirect from an actionResult to another view of another actionresult passing parameter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像你 2024-12-12 04:35:45

像这样使用

如果有多个参数,则:

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

如果只有 id 作为参数,则:

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

Use like this

If there are more than one parameters then:

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

If you have only id as parameter then:

return RedirectToAction("actionname", new { id = "id" });
三寸金莲 2024-12-12 04:35:45
RedirectToAction( new RouteValueDictionary( 
     new{ 
          controller = "mycontroller", 
          action = "myaction", 
          id = "MyId" 
     } 
));
RedirectToAction( new RouteValueDictionary( 
     new{ 
          controller = "mycontroller", 
          action = "myaction", 
          id = "MyId" 
     } 
));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文