asp.net-mvc 在MVC中的不同控制器中从动作重定向到另一个动作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6981017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redirect from action to another action in different controller in MVC
提问by Eslam Soliman
What I want to do is to redirect from an action in "A" controller to an action in "B" controller it gives me this error that it can not find this action in the target controller
我想要做的是从“A”控制器中的一个动作重定向到“B”控制器中的一个动作它给我这个错误,它在目标控制器中找不到这个动作
I am using RedirectToActionMethod any help
我正在使用RedirectToAction方法任何帮助
回答by Bao Duy
You could try this:
你可以试试这个:
return RedirectToAction("kiss", "meoghe");
// RedirectToAction("action name", "controller name");
// meogheController => "meoghe" is controller name
If you use ActionResultfor return type on method, you must use returnfor RedirectToAction.
如果ActionResult在方法上使用for 返回类型,则必须使用returnfor RedirectToAction。
回答by Andras Zoltan
It's probably the case you've reversed the parameter values in your call to RedirectToAction- remember it's actionfirst, then controller. Don't forget that controlleris "Home", too, not "HomeController".
可能是您在调用中颠倒了参数值RedirectToAction- 请记住它是action第一个,然后是controller. 不要忘了,controller是"Home",也没有"HomeController"。
If that still doesn't work - then you've got the action name wrong; or the action you're redirecting to has a filter (e.g. [HttpPost]) that's preventing it from being able to be used.
如果这仍然不起作用 - 那么你的动作名称是错误的;或者您重定向到的操作有一个过滤器(例如[HttpPost]),阻止它被使用。
回答by Eslam Soliman
within your A controller add this in your action
在您的 A 控制器中,将此添加到您的操作中
RedirectToAction(new {controller="B", action="index", id=11,variable="abc"});
that's if you want to send some parameters also ,but do not forget to have a route configured which can map the "variable" parameter as well. I think this is solved in now
那是如果您还想发送一些参数,但不要忘记配置一个也可以映射“变量”参数的路由。我认为现在已经解决了
回答by sirbombay
I did this and it worked fine :)
我这样做了,效果很好:)
return Redirect("/B/index"); //assuming your controller is called BController.
KISS - keep it simple sweetie ;) just pass the url to redirect as string
KISS - 保持简单,亲爱的;) 只需将 url 传递为字符串重定向

