2013-04-01 21 views
0

我有一個HorseController其指數的方法,如:如何在MVC網站中使用屬性路由來翻譯查詢參數?

[GET("Index", TranslationKey = "HorseIndex")] 
    [AllowAnonymous] 
    public ActionResult Index(int? page, HorseTypes? type, HorseGenders? gender, HorseBreeds? breed, HorseJumps? jump, 
     HorseDressages? dressage, String maxAge, String priceFrom, String priceTo, Country? country, bool? hasPicture, bool? hasVideo) 
     { 
... 
} 

我翻譯這樣的路線:

provider.AddTranslations() 
     .ForKey("HorseIndex", new Dictionary<string, string> 
      { 
       { "da", "heste-til-salg" }, 
       { "en", "horses-for-sale" } 
      }) 

的問題是,現在,對於丹麥用戶的網址是:

http://localhost:12623/heste-til-salg?page=1&hasPicture=False&hasVideo=False 

我的問題是如何翻譯查詢參數嗎?我不能在documentation中找到它。

回答

0

我不認爲你可以。 MVC路由中的查詢字符串被視爲傳遞的任何數據的通用傾銷地點,這些數據不適合URL。如果它不是您在設計時不知道的通用數據,那麼它應該只是您網址的一部分。如果它是通用數據,那麼顯然沒有辦法爲查詢字符串中可能出現的任何和所有無關數據提供翻譯。

0

您可以接受已翻譯的參數並在控制器方法中使用StringsLocalized來進行翻譯。