2010-05-26 158 views
0

我在我的簡單的MVC應用程序的兩頁定義了兩個途徑:簡單的ASP.NET MVC路由問題

routes.MapRoute(
    "Results", // Route name 
    "Results/{id}", // URL with parameters 
    new { controller = "Results", action = "Index", 
      id = "" } // Parameter defaults 
); 
routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Main", action = "Index", 
      id = UrlParameter.Optional } // Parameter defaults 
); 

我需要有結果的頁面加載只是一個產品ID像這樣:[MYDOMAIN ....] /結果/ 12345。但是,主頁面也會使用此路由對結果控制器進行POST(使用JQuery)更新:[MyDomain ....]/Main/Update以及數據包。當我只有「默認」路由時,這工作正常。但是當我添加其他「結果」路由時,所有POST更新失敗都失敗。任何想法我做錯了什麼?

非常感謝。

回答

0

我沒有試過這個,但應該完成你所需要的。不知道是否可能有一個「更好」的方式來實現它。

routes.MapRoute(
    "Results", // Route name 
    "Results/{id}", // URL with parameters 
    new { controller = "Results", action = "Index", id = "" } // Parameter defaults 
    new { id = @"\d+" } // regex for id param - id must be a number 
); 
routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Main", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
); 
+0

它的工作!非常感謝你的幫助。 – Robert 2010-05-26 18:07:47