如何在Asp.Net MVC 3中的所有视图中实现@using? [英] How do you implement a @using across all Views in Asp.Net MVC 3?

查看:442
本文介绍了如何在Asp.Net MVC 3中的所有视图中实现@using?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的就是包括这个:

All I want to do is include this:

@using MyProject.WebUI.Properties

在我所有的视图中,而不必在每个视图中都键入它,是否可以在ViewStart或Web.Config中执行此操作?谢谢.

Across all my views without having to type it in each View, is there a way to do that in the ViewStart or Web.Config? Thank you.

推荐答案

将名称空间添加到名称空间元素下的视图web.config中:

Add your namespace to the views web.config under the namespaces element:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MyProject.WebUI.Properties" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

请注意,您可能必须关闭并重新打开要智能感知的视图文件,以使这些更改生效.

Note that you might have to close and reopen the view file that you want intellisense in for these changes to take affect.

这篇关于如何在Asp.Net MVC 3中的所有视图中实现@using?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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