作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想获取默认 Controller 的默认操作方法链接的 URL,这样如果我更改路由配置中的默认 Controller 和操作,那么也应该在 View 中更新。例如
Url.Action(defaultAction,DefaultController);
//output should be like
Url.Action("Index","Home")
最佳答案
假设默认路由名为Default
(在您的RoutesConfig
中):
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
您可以使用Url.RouteUrl
来获取url:
Url.RouteUrl("Default")
参见MSDN
关于asp.net-mvc - 如何在 ASP.NET MVC 中获取默认操作的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37143695/
我是一名优秀的程序员,十分优秀!