Asp.net mvc 如何将命名空间添加到web.config上的Resources文件夹?
我创建了一个新文件夹Asp.net mvc 如何将命名空间添加到web.config上的Resources文件夹?,asp.net-mvc,Asp.net Mvc,我创建了一个新文件夹Resources,在其中添加Languages.resx以创建多语言应用程序。现在,我尝试使用标记将名称空间添加到此文件夹,但它不起作用。我试图创建它,以避免在每个视图中使用MyProject.Resources使用,但我无法使它正常工作 我怎么能这样做 Web.config <system.web> <!--<globalization/>--> <globalization enableClientBasedC
Resources
,在其中添加Languages.resx
以创建多语言应用程序。现在,我尝试使用标记
将名称空间添加到此文件夹,但它不起作用。我试图创建它,以避免在每个视图中使用MyProject.Resources使用,但我无法使它正常工作
我怎么能这样做
Web.config
<system.web>
<!--<globalization/>-->
<globalization enableClientBasedCulture="true" uiCulture="auto" culture="auto"/>
<!--languages-->
<pages>
<namespaces>
<add namespace="MyProject"/>
<add namespace="MyProject.Resources"/>
</namespaces>
</pages>
<!--redireciona caso a sessao tenha expirado ou o usuario nao esteja autenticado-->
<authentication mode="Forms">
<forms defaultUrl="~/Home/Index" loginUrl="~/Home/Index" slidingExpiration="true" timeout="60" />
</authentication>
<!-- ativa o custom errors
<customErrors mode="On" defaultRedirect="~/ErrorPage/NotFound">
<error statusCode="404" redirect="~/ErrorPage/NotFound"/>
</customErrors> -->
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
尝试使用
Html
<h1>@Language.Name</h1>
@Language.Name
需要将名称空间
添加到应用程序的/Views
文件夹(在
部分)中的web.congfig
文件中
....
....
....
mvc项目中有多个web.confg文件。您是否对视图文件夹中的web.config进行了更改?哪个web.config
?-应该是视图
文件夹(在
下)中的一个,你们都很好。现在它起作用了。谢谢。
<configuration>
....
<system.web.webPages.razor>
....
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
....
<add namespace="MyProject"/>
<add namespace="MyProject.Resources"/>
</namespaces>
</pages>
</system.web.webPages.razor>