Click here to Skip to main content
14,447,320 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi there,

I have to develop a web application in MVC3 or MVC4. It has to support multilingual functionality across all pages. The application is developed in VS 2008 and implementing the multilingual support using Database. I have to re-develop the entire application using MVC3/MVC4.

I am planning to use resource files. So when a user changes the selected language either from a drop down or any other button click then the views must me updated with the text in the selected language. How do i dynamically access the appropriate resource file? Each language would have a resource file.

I tried using the database and able to send the data with updated selected language text back to the View from the controller but the text is not updated for some reason.

<label for="SelectLanguage"> @if (Model == null)
                                                       {@Html.Label("UI Language")}
//NOTE: the below value in variable txt comes up perfectly fine but not assigned to the label
                                                           var txt = Model.UIText.Where(m1 => m1.ID == "li007").FirstOrDefault().LangValue;

This is my first attempt with MVC

Thanks in advance
Rate this:
Please Sign up or sign in to vote.

Solution 1

You should create a model class and use @Html.LabelFor, unless you're not doing any POSTing and using AJAX. I am not sure that what you've done here will work. Your model should expose a UIText property that is exactly what you need, the lookup should be in that class. Then @Html.LabelFor(Model.UIText) would be fine.

I feel like I answered only half your question. There's actually an article on this site for what you want. Here.[^]
Sreedevi Pidaparthi 24-Aug-12 1:01am
Thanks for quick response Christian Graus.

I have already considered the link u suggested..

My model has UIText exposed already. See below:

public class PageLanguageData
public string ID { get; set; }
public string LangValue { get; set; }

public class LogOnModel
[Display(Name = "User name")]
public string UserName { get; set; }

[Display(Name = "Password")]
public string Password { get; set; }

[Display(Name = "Select Language")]
public string SelectLanguage { get; set; }

[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }

public List<PageLanguageData> UIText { get; set; }


i am invoking a controller method which fetches the selected language data from db and i am refreshing the LogOn view after that. I am getting the correct data in the Model.UIText after refresh but the label text is not updated.

my javascript/jquery method for invoking the controller action

$(document).ready(function () {
$('#ddlLanguage').change(function () {
var value = $("#ddlLanguage option:selected").val();
var url = "/Account/ChangeUI?li:" + value;

I have an id against each text i need to update. ID is common for all languages.

Hope this info helps.
Christian Graus 24-Aug-12 6:54am
OK - well, the core issue as far as I can see is that you should have properties on your viewmodel, which all look up the right string based on the language, and that you bind to directly. You can't be doing var txt = Model.UIText.Where(m1 => m1.ID == "li007").FirstOrDefault().LangValue on every string you display. If this lookup works, then you need to move it in to your ViewModel, as I said before. If you do that, does it work ?
Rate this:
Please Sign up or sign in to vote.

Solution 2


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100