if you want a solution with ViewModel class, you can pick up these:
For wrapping City with it's selected LocalLanguage
public class CityLocolized
{
public City City { get; set; }
public String LocalName { get; set; }
}
Here, we chose the either default so with if else no join, else chose from CityCulture table
string lang = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
List<CityLocolized> citiesLocalized = null;
if (lang == "en") // which is default in db
{
citiesLocalized = (from c in fke.Cities
select new CityLocolized
{
City = c,
LocalName = c.Name
}
).ToList();
}
else // for other languages
{
citiesLocalized = (from c in fke.Cities
join cc in fke.CityCultures
on c.Id equals cc.CityId
where cc.LangId == lang
select new CityLocolized
{
City = c,
LocalName = cc.LocalName
}).ToList();
}
and this one for passing View:
ViewData["CitiesLocolized"] = new SelectList(citiesLocalized, "City.Id", "LocalName");
finally at view:
<%:Html.DropDownListFor(model => model.CityId, ViewData["CitiesLocolized"] as SelectList)%>
i think this is it.
moguzalp
moguzalp
2010-10-30 16:38:31