【问题标题】:How do I return a method paramenter with RedirectToAction如何使用 RedirectToAction 返回方法参数
【发布时间】:2010-02-11 16:35:05
【问题描述】:

目前我有两个方法签名。

public ActionResult Edit(bool? failed)

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(FormCollection collection)

在密码更新失败时的 Update 方法中,我想返回失败 == true 的 Edit 操作。但是使用该行

return RedirectToAction("Edit", true);

似乎没有实现这一点。 (我确实在 Edit Action 结束,但 bool 值为 null。)我怎样才能重定向到一个动作并仍然保持 bool 值?

谢谢

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    你很接近 - 试试这个:

    return RedirectToAction("Edit", new { failed = true });
    

    【讨论】:

      【解决方案2】:

      恐怕 RedirectToAction 没有那么简单……您需要将参数作为路由值字典传递。试试:

      return RedirectToAction("Edit", new { failed = true }); 
      

      http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-26
        • 2021-07-25
        相关资源
        最近更新 更多