日期:2014-05-17  浏览次数:20354 次

RegisterRoutes
Global.asax.cs
C# code

namespace Tomato.WebVideo
{

    public class MvcApplication : HttpApplication
    {

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default" , // Route name  问题1:这个"Default"和下边的"Paging" 只是路由的名称对吗? 可以任意取,只是为了以后查找的方便?
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults  
//问题2:这里是在设置默认值吗?   UrlParameter.Optional 表示可选对吗?
            );
            routes.MapRoute(
                "Paging" ,                                              // Route name
                "{controller}/{action}/{id}/page{pageIndex}",//问题3:controller是控制器名,action是里边的方法名,id对应的是什么? 
                new { pageIndex = 1 }
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}





------解决方案--------------------
1.路由名称,可以通过它访问该路由,比如:
C# code
RouteTable.Routes["Default"]