简体   繁体   English

如何使用RedirectToAction返回方法参数

[英]How do I return a method paramenter with RedirectToAction

I have two method signatures at the moment. 我目前有两个方法签名。

public ActionResult Edit(bool? failed)

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

In the Update method when the password update fails I want to return to the Edit action with failed == true. 在更新方法中,当密码更新失败时,我想返回失败== true的“编辑”操作。 However using the line 但是使用线

return RedirectToAction("Edit", true);

doesn't seem to achieve this. 似乎没有实现这一目标。 (I do end up at the Edit Action but the bool value is null.) How else can I redirect to an action and still have the bool value hold? (我的确结束于“编辑操作”,但bool值为null。)如何将我重定向到某个操作并仍然保持bool值?

Thanks 谢谢

您接近-试试这个:

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

I'm afraid RedirectToAction isn't as simple as that... you need to pass the parameter as a route value dictionary. 恐怕RedirectToAction并不那么简单...您需要将参数作为路由值字典传递。 Try: 尝试:

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

See http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction.aspx 请参阅http://msdn.microsoft.com/zh-cn/library/system.web.mvc.controller.redirecttoaction.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 最小起订量:如何模拟具有函数回调作为参数的方法 - Moq: How to Mock method with function callback as paramenter 如何返回JSON或RedirectToAction? - How to either return JSON or RedirectToAction? 使用 RedirectToAction 时如何维护 ModelState 错误? - How do I maintain ModelState errors when using RedirectToAction? 如何将一个类的名称作为参数传递给方法,并在方法内部实例化该类? - How to pass the name of a class as paramenter to a method and instantiate that class inside the method? 如何设置返回DbParameter的方法? - How do I setup a method to return a DbParameter? 如何为该方法返回2个值? - How do I return 2 values for this method? 如何调用将返回到调用控制器但也可以具有 RedirectToAction 的控制器操作 - How Do You Call a Controller Action That Will Return to The Calling Controller But Also Can Have A RedirectToAction 如何使用 RedirectToAction 方法从控制器重定向 - How to redirect from controller using RedirectToAction method RedirectToAction如何指定action http方法? - How to RedirectToAction specifying the action http method? 如何使用 RedirectToAction 方法添加查询字符串值? - how to add querystring values with RedirectToAction method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM