如果我申请[Route(Name =“WhatEver”)]作为默认站点路由,我在访问站点根时得到HTTP 404。RouteAttribute破坏了我的默认路由
例如:
- 创建新的样本MVC项目。
属性添加路由:
// file: App_Start/RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapMvcAttributeRoutes(); // Add this line routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } }
现在添加路由属性
[RoutePrefix("Zome")] public class HomeController : Controller { [Route(Name = "Zndex")] public ActionResult Index() { return View(); } ... }
而且,当您启动了调试运行项目,你将有HTTP错误404。我应该如何使用默认路由映射的属性路由?
什么是后面使用'〔路线(名称= “Zndex”)]为'Index'动作'属性的目的是什么? '[domain]/Zome'会自动引用'[domain]/Zome/Index',使用'RouteAttribute'可能需要'[domain]/Zome/Zndex'到达'Index'操作。 –
我认为路由名不用于路由匹配,所以''[domain]/Zome/Zndex'指向任何地方。我需要在Index动作上使用路由名称,因为我想使用Url助手,路由名称如下所示:'Zndex page' –