asp.net mvc2 學習筆記

1、asp.net mvc2 路由規則:

例子:
    routes.MapRoute(
    "test",
     "test/test-{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]" }
     );  
1.若是有多個路由路徑,從上往下匹配,匹配成功執行對Controller,匹配不成功返回404錯誤
2.url=test/test-{city}-{price}-{star},Controller或action配置固定參數,會使用默認的Controller或action 值,(若是{Contrller}或{action}爲路徑,能夠不加Controller 、action默認參數)。

2、action 參數填充方式:
1.Model填充,根據model成員一一匹配填充,若是有多個同名action,且有model填充的action,model action,應加[HttpPost]加以區分,不然不能匹配。 
2.通常變量填充,從左至右依次填充
相關文章
相關標籤/搜索