MVC3 / MVC4多语言Web应用程序 [英] MVC3/MVC4 Multilingual Web Application

查看:67
本文介绍了MVC3 / MVC4多语言Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我必须在MVC3或MVC4中开发Web应用程序。它必须支持所有页面的多语言功能。该应用程序在VS 2008中开发,并使用数据库实现多语言支持。我必须使用MVC3 / MVC4重新开发整个应用程序。



我打算使用资源文件。因此,当用户通过下拉菜单或任何其他按钮单击更改所选语言时,必须使用所选语言的文本更新视图。 如何动态访问相应的资源文件?每种语言都有一个资源文件。



我尝试使用数据库并能够将更新后的选定语言文本的数据从控制器发送回View但文本由于某种原因没有更新。



< label for =SelectLanguage> @if(Model == null)
{@ Html.Label(UI Language)}
else
{
//注意:变量txt中的以下值出现完全没问题,但没有分配给标签
var txt = Model.UIText.Where(m1 => m1.ID ==li007)。FirstOrDefault()。LangValue;
@ Html.Label(txt);}< / label>





这是我第一次使用MVC



提前致谢

Sree

解决方案

你应该创建一个模型类,使用@ Html.LabelFor,除非你没有做任何POST并使用AJAX。我不确定你在这里所做的事情是否奏效。您的模型应该公开一个您需要的UIText属性,查找应该在该类中。那么@ Html.LabelFor(Model.UIText)就可以了。



我觉得我只回答了你问题的一半。实际上这个网站上有一篇文章可以满足您的需求。 此处。 [ ^ ]


对于多语种网站教程,您可以访问以下2个链接,用于ASP.NET Webform& ASP.NET MVC4。



http://dotnetawesome.blogspot.com/2014/09/how-to-create-multilingual-website-in-aspnet-mvc4.html



http:// dotnetawesome。 blogspot.com/2014/06/how-to-create-multilingual-application-aspnet.html

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")}
                                                       else
                                                       {
//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;
                       @Html.Label(txt);}</label>



This is my first attempt with MVC

Thanks in advance
Sree

解决方案

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.[^]


For the Multilingual Website Tutorial you can visit this below 2 links for ASP.NET Webform & ASP.NET MVC4.

http://dotnetawesome.blogspot.com/2014/09/how-to-create-multilingual-website-in-aspnet-mvc4.html

http://dotnetawesome.blogspot.com/2014/06/how-to-create-multilingual-application-aspnet.html


这篇关于MVC3 / MVC4多语言Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆