gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET MVC 中获取默认操作的 URL

转载 作者:行者123 更新时间:2023-12-03 05:37:55 26 4
gpt4 key购买 nike

我想获取默认 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com