[英]ASP.NET MVC RedirectToAction Default Action
How do I redirect to a Controller without defining the Action? 如何在不定义操作的情况下重定向到控制器? (it will default to the default action as defined in the routes config) (它将默认为路由配置中定义的默认操作)
Example return RedirectToAction("Index", "Error" new { messageId = errorMessageId} );
示例 return RedirectToAction("Index", "Error" new { messageId = errorMessageId} );
Url displayed to user is: http:mydomain/Error/Index/1001
显示给用户的网址是: http:mydomain/Error/Index/1001
Preferred return RedirectToAction(null, "Error" new { messageId = errorMessageId} );
首选 return RedirectToAction(null, "Error" new { messageId = errorMessageId} );
URL I want to displayed to user is: http:mydomain/Error/1001
我要显示给用户的URL是: http:mydomain/Error/1001
When I type the URL manually, it works fine, so I know my routes are working. 当我手动键入URL时,它可以正常工作,因此我知道我的路由正常。
I just cant figure out how to do it using Redirectxxxx in MVC. 我只是不知道如何使用MVC中的Redirectxxxx来做到这一点。
You can use RedirectToRoute
. 您可以使用RedirectToRoute
。
return RedirectToRoute(new { controller = "Error", messageId = errorMessageId });
Alternatively, there is Redirect
coupled with Url.RouteUrl
. 另外,也可以Redirect
与Url.RouteUrl
耦合。
return Redirect(Url.RouteUrl(new { controller = "Error", messageId = errorMessageId }));
protected internal RedirectToAction(
string actionName,
string controllerName,
object routeValues
)
Here is the RedirectToAction method you can define your own route here without using the action name. 这是RedirectToAction方法,您可以在此处定义自己的路由,而无需使用操作名称。
For more info about routing check this: Routing 有关路由的更多信息,请检查以下内容: 路由
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.