很惊讶地看到NerdDinner路由文件只有一个自定义路由。证明如果您遵循约定,您可以“开箱即用”使用路由处理程序。
namespace NerdDinner {
public class MvcApplication : System.Web.HttpApplication {
public void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"UpcomingDinners",
"Dinners/Page/{page}",
new { controller = "Dinners", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
void Application_Start() {
RegisterRoutes(RouteTable.Routes);
}
}
}