2013-04-17 54 views
0

我有兩個途徑的mvc路線沒有采取默認值

routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 

routes.MapRoute(
      name: "CustomRoute", 
      url: "{country}/{lang}/{controller}/{action}", 
      defaults: new { controller = "Test", action = "Index" } 
     ); 

,但我只能查看在我CustomRoute喜歡的東西/ ES/ES /測試/動作,如果我試圖用類似/ ES/ES /我有404錯誤,它沒有找到頁面,我真的需要/ ES/ES /方式。一些想法爲什麼不在CustomRoute中使用默認值? ... 提前致謝。

+0

你爲什麼要創建一個問題嗎? –

+0

@vonv。我以爲我對你有些壓力,我有點慚愧 – Steve

+0

沒有必要感到羞恥,人們在這裏互相幫助,建立一個內容豐富的偉大維基網站。那麼你的問題解決了嗎?在所有?如果是,那麼你可以刪除這一個,如果它沒有任何用處,並且「它真的是重複的」。 –

回答

0

你可以看到示例代碼:

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

    routes.MapRoute(
     "CustomRoute", // Route name 
     "{country}/{lang}/{controller}/{action}", // URL with parameters 
     new { country = "MyContry", lang = "Mylanguage", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
    );