我的项目命名空间添加到MVC的web.config [英] Add my project namespace to MVC web.config

查看:76
本文介绍了我的项目命名空间添加到MVC的web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能我的项目命名空间添加到Web.config这样的Razor视图引擎包括我在我的项目中的所有页面项目命名空间?像这样:

Can I not add my project namespace to the web.config so that the Razor view engine includes my project namespace for all pages in my project? Like so:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.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.Optimization"/>
        <add namespace="System.Web.Routing" />

        <add namespace = "MyProjectNamespace.NestedNamespace"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

这是行不通的。

推荐答案

这是一个老问题,但显然还是有一点与Visual Studio(2015年截至目前)的问题。加入命名空间的web.config文件中的视图文件夹,关闭并重新打开所有的意见后。该命名空间是不承认,直到我关闭了他们所有的意见将不断抛出运行时错误。

This is an old question, but apparently there is still a bit of a problem with Visual Studio (2015 as of right now). After adding the namespaces to the web.config file in your Views folder, close and re-open all views. The namespaces were not recognized and the views would continuously throw runtime errors until I closed them all.

这篇关于我的项目命名空间添加到MVC的web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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