繁体   English   中英

ASP.Net MVC 找不到未包含在控制器中的命名空间

[英]ASP.Net MVC can't find a namespace that is not included in the controller

当我尝试运行此控制器操作时,出现错误:

Compiler Error Message: CS0234: The type or namespace name 'ViewModels' does not exist in the namespace 'App.Models' (are you missing an assembly reference?)

Line 28:     using App.Web.Mvc;
Line 29:     using App.Models;
Line 30:     using App.Models.ViewModels;

问题是App.Models.ViewModels在控制器中没有对App.Models.ViewModels引用,所以我不知道为什么会出现错误,第 30 行 simple 在我的项目中不存在任何地方!

发现 Razor 会将在您的视图文件夹中的 Web.Config 文件中指定的命名空间的引用添加到您的视图的编译文件的顶部。 所以刚刚删除了 webconfig 中的引用

视图/Web.config:

<system.web.webPages.razor>
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="App.Models.ViewModels" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM