【发布时间】:2016-05-10 16:04:12
【问题描述】:
我想获取默认控制器的默认操作方法链接的 URL,这样如果我在路由配置中更改默认控制器和操作,那么也应该在视图中更新。 例如
Url.Action(defaultAction,DefaultController);
//output should be like
Url.Action("Index","Home")
【问题讨论】:
标签: asp.net-mvc
我想获取默认控制器的默认操作方法链接的 URL,这样如果我在路由配置中更改默认控制器和操作,那么也应该在视图中更新。 例如
Url.Action(defaultAction,DefaultController);
//output should be like
Url.Action("Index","Home")
【问题讨论】:
标签: asp.net-mvc
假设默认路由命名为Default(在你的RoutesConfig中):
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
您可以使用Url.RouteUrl获取网址:
Url.RouteUrl("Default")
见MSDN
【讨论】: