我有`
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
//routes.Add(new SubdomainRoute());
routes.MapRoute("Default", "{controller}/{action}", new
{
controller = "Home",
action = "Index"
});
routes.MapMvcAttributeRoutes();
}
我管理mvc默认模板所依赖的很多路线(菜单,帐户,注册等)
我想尝试将/ home / contact更改为简单/联系,所以我通过定义(HomeController)
来做逻辑事情 [Route("about", Name = "About")]
public ActionResult About()
{...}
这不会触发,但是如果我注释掉代码的第一部分,则会调用此代码。
答案 0 :(得分:3)
路线登记的顺序很重要。你需要打电话
routes.MapMvcAttributeRoutes();
之前
routes.MapRoute("Default", "{controller}/{action}", new
{
controller = "Home",
action = "Index"
});