[英]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.