我下载了这个的例子http://www.cnblogs.com/zhangziqiu/archive/2009/02/28/ASPNET-MVC-2.html
规则是这样的:
         #region 酒店频道部分
            // hotels/list-beijing-100,200-3
            routes.MapRoute(
                "酒店列表页",
                "hotels/{action}-{city}-{price}-{star}",
                new { controller = "Hotel", action = "list", city = "beijing", price="-1,-1", star="-1" },
                new { city=@"[a-zA-Z]*",price=@"(\d)+\,(\d)+", star="[-1-5]"}
                );            //hotels/所有匹配
            routes.MapRoute(
                "酒店首页",
                "hotels/{*values}",
                new { controller = "Hotel", action = "default", hotelid = "" }
                );
            #endregion            //网站首页.
            routes.MapRoute(
                 "网站首页",
                 "{*values}",
                 new { controller = "Home", action = "index"}
                 );  control是这样的:
      public ActionResult Default()
        {
            return View();
        }        public ActionResult List(string city, string price, int star)
        {
            this.ViewData["city"] = city;
            string[] tempPrice = price.Split(',');
            this.ViewData["startPrice"] = Convert.ToInt32(tempPrice[0]);
            this.ViewData["endPrice"] = Convert.ToInt32(tempPrice[1]);
            this.ViewData["star"] = star;
            return View("List");
        }view是这样的:
<body>
    <div>
        <div>搜索条件</div>
        <div>城    市: <%= this.ViewData["city"].ToString() %></div>
        <div>价格范围:<%= this.ViewData["startPrice"].ToString()%> - <%= this.ViewData["endPrice"].ToString()%></div>
        <div>酒店等级:<%= this.ViewData["star"].ToString()%></div>
    </div>
</body>==============
我执行
localhost/hotels/list-beijing-100,200-3 
显示的是:
搜索条件城 市: beijing价格范围:100 - 200酒店等级:3----
就是不明白  public ActionResult List(string city, string price, int star)
的参数是怎么传进去的。请高手指点。

解决方案 »

  1.   

    就是不明白 public ActionResult List(string city, string price, int star)
    就是这样啊如果,URL的形式如下
    http://www.xxx.com/List?ctity=2&price=5&star=8然后,你在action内面,就直接用方法上面的参数就可以了。MVC将自动的将URL的参数和方法上的参数一一对应,放值进去,它很聪明。
      

  2.   

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult CourseDetails(int id,string courseId) 

    StudentDataAccess stu = new StudentDataAccess(courseId); 
    return View(stu); 
    } <%=Html.ActionLink(Model.GetStudy()[i].CourseName, "CourseDetails", new {id=Model.StudentId, courseId = Model.GetStudy()[i].CourseNumber })%>