为什么此号召性用语不提供操作方法名称?
@Url.Action("Index","NewStore")
它只是产生...
localhost/TemplateUI/en-CA/Atomic/Wassabi/Store
我需要它在最后产生 /index ....
为什么此号召性用语不提供操作方法名称?
@Url.Action("Index","NewStore")
它只是产生...
localhost/TemplateUI/en-CA/Atomic/Wassabi/Store
我需要它在最后产生 /index ....
那是因为Url.Action助手使用您在 Global.asax 中的路线注册。而且由于您是Index作为操作名称传递的,我猜在您的路由注册中您已经指定了 的默认值action="Index",所以它被省略了。
例如,如果您有以下默认路由:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "Home", action = "Index" }
);
}
因为controller = "Home"和action = "Index"约束都已指定,/并且/Home将是绝对等效的 url 并调用控制器的Index操作。Home
因此,当您尝试使用一些帮助程序构建 url 时也会发生同样的情况:它使用您的路由。
如果您需要在 url 中包含操作名称,请确保您已删除action路由定义中的约束。