开发者

Global NameSpace + MVC3?

开发者 https://www.devze.com 2023-03-23 15:47 出处:网络
I don\'t know what i\'m doing wrong here. I\'m using a namespace in both my views and controllers. I decided i needed to make it a global namespace because i\'m using it all over. Anyways i first adde

I don't know what i'm doing wrong here. I'm using a namespace in both my views and controllers. I decided i needed to make it a global namespace because i'm using it all over. Anyways i first added it to my main web.config. I was still getting compiler errors. So i did a search and apparently razor has its own web.config too. So i added the namespace there too. I'm still getting compiler errors. Is the main web.config used for the controller & the views web.config just used for the razor views? What am i doing wrong?

More information requested:

--main web.config

   <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages"/>
    <add namespace="RunLogSite.POCOs"/>
  </namespaces>

--views web.config

<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" />开发者_Python百科;
    <add namespace="System.Web.Routing" />
    <add namespace="RunLogSite.POCOs"/>
  </namespaces>
</pages>

Error: Error 1 The type or namespace name 'Run' could not be found (are you missing a using directive or an assembly reference?) D:\Users\Brent\documents\visual studio 2010\Projects\RunLog\RunLog\Controllers\RunsController.cs 27 32 RunLogSite

If i add at the following at the top of the page it is fixed:

using RunLogSite.POCOs;


Error: Error 1 The type or namespace name 'Run' could not be found (are you missing a using directive or an assembly reference?) D:\Users\Brent\documents\visual studio 2010\Projects\RunLog\RunLog\Controllers\ RunsController.cs 27 32 RunLogSite

Check the file where you are getting the error. Namespaces in web.config are only relevant to views, you still need to define all using in all cs files.


Are you sure you are adding the namespace correctly, as per below ...

<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="Your.Custom.Namespace" />
    </namespaces>
</pages>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号