2011-03-24 125 views

回答

6
public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.MapRoute(
      "About", // Route name 
      "About", // URL 
      new { controller = "Home", action = "About" }); 

     ... 

    } 

@Scott:谢谢。修复。

+0

把/在URL的开头会导致一个ArgumentException错误 – 2011-03-24 20:34:45

3
routes.MapRoute(
    "About", 
    "About", 
    new { controller = "Home", action = "About" } 
    ); 

只要确保它是默认的路由处理之前的地方。

1

添加路由:

routes.MapRoute(
    "About", 
    "About" 
    new { controller = "Home", action = "About" }); 

既然是硬编码的,你要确保它是有各种PARAMS占位符的任何路由之前。

​​
1

这样的默认路由之前创建一个新的路线

routes.MapRoute(
    "HomeActions", 
    "{action}", 
    new 
    { 
     controller  = "Home", 
     action   = "Index" // I technically don't think this is required. 
    }, 
    new // The second object are route constraints 
    { 
     action   = "Index|FAQ|ContactUs|Examples|Materials|Members" // <-- various actions on my home controller. Any regex works here. 
    }); 
0

我用这个::