2012-04-13 42 views
0

嗨我想利用great article在我的mvc3網站上提供本地化功能。如果沒有區域是可以正常使用,但將在我的網站領域我得出這樣的問題:htmlHelper.RouteLink不生成我想要的網址

htmlHelper.RouteLink(linkText, globalisedRouteData) 

其中globalisedRouteData:

4 Keys: Culture, Area, Controller, Action 
4 values: en, soluciones, home, index 

沒有產生預期的(對我來說):主機/ EN/SOLUCIONES/home /索引 但是:/ soluciones/Home?culture = en

什麼是打破我這是?文化= en。爲什麼沒有被嵌入到/ en /中,因爲它包含在globalisedRouteData中?

在我的RegisterRoutes,我放在:

 const string defautlRouteUrl = "{area}/{controller}/{action}/{id}"; 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     RouteValueDictionary defaultRouteValueDictionary = new RouteValueDictionary(new {area="soluciones_de_salud", controller = "Home", action = "Index", id = UrlParameter.Optional }); 
     routes.Add("DefaultGlobalised", new GlobalisedRoute(defautlRouteUrl, defaultRouteValueDictionary)); 

Thanks¡¡

回答

0

我相信你需要改變使用 '身份證' 到 '文化'

const string defautlRouteUrl = "{area}/{controller}/{action}/{culture}"; 

RouteValueDictionary defaultRouteValueDictionary = new RouteValueDictionary(new {area="soluciones_de_salud", controller = "Home", action = "Index", culture = UrlParameter.Optional }) 

當發生路由綁定時,參數名稱必須與路由參數相匹配,否則最終會導致無線連接日

?ParamName=Value  (?culture=en) 
0

嘗試改變idculture

如果文化是在你的URL必須也刪除id = UrlParameter.Optional

const string defautlRouteUrl = "{area}/{controller}/{action}/{culture}"; 
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
RouteValueDictionary defaultRouteValueDictionary = new RouteValueDictionary(new {area="soluciones_de_salud", controller = "Home", action = "Index" }); 
routes.Add("DefaultGlobalised", new GlobalisedRoute(defautlRouteUrl, defaultRouteValueDictionary)); 

如果文化是不是強制性的,你會設置一個默認值

const string defautlRouteUrl = "{area}/{controller}/{action}/{culture}"; 
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
RouteValueDictionary defaultRouteValueDictionary = new RouteValueDictionary(new {area="soluciones_de_salud", controller = "Home", action = "Index", culture = "en" }); 
routes.Add("DefaultGlobalised", new GlobalisedRoute(defautlRouteUrl, defaultRouteValueDictionary));