C# 是否可以在我的 aspx 视图中使用“using”语句?(ASP.NET MVC)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1697169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 20:02:23  来源:igfitidea点击:

Is it possible to use the 'using' statement in my aspx views? (ASP.NET MVC)

c#asp.netasp.net-mvc

提问by UpTheCreek

This likely applies to non MVC too. But, Is it possible to use the 'using' statement in my aspx views?

这也可能适用于非 MVC。但是,是否可以在我的 aspx 视图中使用“using”语句?

Reason is that I have the pages reference resource files for localised strings. And some of these resource references are quite long - it's really cluttering my code.

原因是我有本地化字符串的页面引用资源文件。并且其中一些资源引用很长 - 它真的使我的代码变得混乱。

Since most of the time these resources are in a namespace specifially for the view, I'd just like to put a 'using Resources.This.that' at the top of the page. I don't seem to be able to though - is there a way?

由于大多数情况下这些资源都位于专门用于视图的命名空间中,因此我只想在页面顶部放置一个“使用 Resources.This.that”。我似乎无法做到 - 有办法吗?

Thanks

谢谢

采纳答案by UpTheCreek

Do you mean like

你的意思是喜欢

<%@ Import namespace="MyProgram.MyNamespace" %>

Also, inside the root <configuration>tag of web.config, you can add:

此外,在<configuration>web.config的根标签内,您可以添加:

<system.web>    
    <pages>
       <namespaces>
          <add namespace="System" />
          <add namespace="System.Collections" />
          <add namespace="System.Collections.Specialized" />
          <add namespace="System.Configuration" />
          <add namespace="System.Text" />
          <!-- etc -->
       </namespaces>
    </pages>
</system.web>