不好意思,兄弟我在mvc上是初级选手。估计标题没问清楚。我新建了一个mvc的项目,里边的globle里边的routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Default", id = UrlParameter.Optional } // Parameter defaults
            );
这个玩意我没咋变动。在mvc项目里所有的页面的url规则都按这个来执行也就是说student/index/25
可以查询到编号为25的学生的信息。但是我有个其他页面,想换个规则
student/index/1998/12/25
这个url的规则是找到1998/12/25日的学生课程安排信息。
这个route的定义,在哪儿定义呀,能另外再定义一套吗?不知道我问清楚了没,谢谢~

解决方案 »

  1.   

    可以另外定义
    在第一个的后面定义
    ....之前定义的"Default", // Route name
      "{controller}/{action}/{year}/{month}/{date}", // URL with parameters
      new { controller = "Home", action = "Default", id = UrlParameter.Optional ,year="2010",month="04",date="14"} // Parameter defaults
      );
      

  2.   

    "Student", // Route name
      "Student/{action}/{year}/{month}/{date}", // URL with parameters
      new { controller = "Student", action = "Index", year="2010",month="04",date="14" } // Parameter defaults
      );所有Student控制器都会走这个路由,如果你只想定义一个操作,把{action}换成具体的就行了一定要放到默认配置的前面
      

  3.   


    //自定义的分页路由,示例项目中的“自定义路由分页”示例中用
                routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",
                                new
                                    {
                                        controller = "Orders",
                                        action = "EmployeeOrders",
                                        emplyeeId = "1",
                                        pageIndex = UrlParameter.Optional
                                    });感谢各位的回复。研究了一上午route仍旧有点蒙蒙的。
    我下了套“MvcPager分页控件”的源代码,看到有个route怎么都无法理解。routes.MapRoute("Paging", "{controller}/{action}/employee_{employeeId}/page_{pageIndex}",……
    请看,难道形成的url应该是
    /Orders/EmployeeOrders/employee_n/n
    可是当n是1的时候,无法找到该页面呀。
    我浏览的时候其实页面是这样的:
    http://localhost:2402/Orders/Index/2那个朋友能给清晰的解释下,谢谢呀~