0

I cam across this thread that ask how to access local resource and he solved his own problem but my situation is a little bit different.

Areas>Models>Support>Localization
                             MyResouces.resx
                     SupportModel

Inside my SupportModel I want to access values from Localization/MyResouces.resx. What is the syntax?

One solution is to use HttpContext.GetLocalResourceObjec(virtual path, key) but it has not worked for me. I have used

GetLocalResourceObject("~/Areas/Models/Support/SupportModel", "option1Text")

I also renamed the Localization folder to App_LocalResources but that did not solve the problem. May I am doing something wrong?

Note that I have modified my code as I did not want to post the real code. Thx

4

4 回答 4

1

要访问 Localization/MyResouces.resx 中的值,请尝试以下操作:

@Areas.Models.Support.Localization.MyResouces.option1Text

语法:[namespace].[ResourceName].[Property]

前提是您的 MyResouces.resx 文件具有public访问修饰符。

于 2013-08-22T09:20:01.797 回答
0

您可以使用以下语法在视图中访问它:

@Resources.IndexPage.PropertyName

并且您必须确保您的资源文件具有以下属性: 构建操作:嵌入式资源自定义工具:PublicResXFileCodeGenerator 自定义工具命名空间:Resources.IndexPage(这是您提供的命名空间,它在视图中用于访问属性。

看看这篇文章: http: //www.chambaud.com/2013/02/27/localization-in-asp-net-mvc-4/

于 2014-03-10T17:14:40.513 回答
0

我使用的解决方案是这样的。有趣的是,网上没有可用的解决方案。

using Myproject.Areas.Models.Support.Localization;
...
MyResouces.option1

以上并不是实际编译的代码。

于 2013-08-22T13:18:28.670 回答
0

我在 Models/Support 中创建了一个带有 Resource1.resx 文件的示例应用程序,这就是我从中获取值的方式:

public ActionResult Login(string returnUrl)
    {
        var res = Models.Support.Resource1.TestString1;  // this is resource created inside Models/Support/
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }
于 2013-08-22T01:04:13.037 回答