Got it working.Bizarrely i just created a new project and started again and it all works fine. All the different ways people have suggested worked in the new project. I have yet to find out what the difference is between the 2 projects.
Cheers
Johnny
</div>
Marked as answer by ricka6 on Feb 03, 2010 08:48 PM
I had the same problem and I lost some hours for this issue.
I was overriding the Initialize method of the Controller and I was setting the culture of the current thread. This approach is not enough!! It seems that the ViewPage changes the culture again.
The problem ist the directive of ViewPage => Culture="auto" UICulture="auto". If you remove them than it works!!!
superspit
0 Points
2 Posts
Asp.net Mvc 2.0 RC Setting Thread CurrentCulture/Ui
Feb 02, 2010 03:59 PM|LINK
I been pulling my hair out all day.
i can't seem to set the current thread cultureui or culture to anything other than English. In the controller i have
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); CultureInfo cultureInfo = CultureInfo.GetCultureInfo("fr-FR"); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; }in my view i have
<%= Thread.CurrentThread.CurrentUICulture.EnglishName%>
the thread seems to be fine but as soon as the view renders some how its back to english!!
I know its a RC, so is it broken or am I missing something ??
cheers
Johnny
ignatandrei
All-Star
137670 Points
22146 Posts
Moderator
MVP
Re: Asp.net Mvc 2.0 RC Setting Thread CurrentCulture/Ui
Feb 02, 2010 08:14 PM|LINK
I have MVC2 ... I followed your steps, but ...In the view and in the controller it gives me French(France)
DO you have some settings in Web.Config ?
levib
Star
7702 Points
1099 Posts
Microsoft
Re: Asp.net Mvc 2.0 RC Setting Thread CurrentCulture/Ui
Feb 03, 2010 12:26 AM|LINK
Try setting the culture from within Application_BeginRequest() (in Global.asax) rather than from within the Controller.
superspit
0 Points
2 Posts
Re: Asp.net Mvc 2.0 RC Setting Thread CurrentCulture/Ui
Feb 03, 2010 08:12 AM|LINK
Got it working.Bizarrely i just created a new project and started again and it all works fine. All the different ways people have suggested worked in the new project. I have yet to find out what the difference is between the 2 projects.
Cheers
Johnny
</div>DanielC.
Member
64 Points
24 Posts
Re: Asp.net Mvc 2.0 RC Setting Thread CurrentCulture/Ui
Jul 22, 2010 01:00 PM|LINK
I had the same problem and I lost some hours for this issue.
I was overriding the Initialize method of the Controller and I was setting the culture of the current thread. This approach is not enough!! It seems that the ViewPage changes the culture again.
The problem ist the directive of ViewPage => Culture="auto" UICulture="auto". If you remove them than it works!!!
Anyway my approach and suggestion is:
-override InitializeCulture of ViewPage
protected override void InitializeCulture() { base.InitializeCulture(); CultureInfo culture = new CultureInfo("it"); //set culture you want System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; }-override Initialize of the Controllerprotected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); CultureInfo culture = new CultureInfo("it"); System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; }I hope it helps.
Bye