简体   繁体   English

ASP.NET MVC找不到我的名称空间

[英]ASP.NET MVC can't find my namespace

I'm developing a simple blog system and I'm stuck on a position. 我正在开发一个简单的博客系统,并且处于困境。 I want to refer an external library Components, where I have Article class. 我想引用一个外部库组件,这里有Article类。 Trying to set the type of the model in the view @model Components.Article I', receiving an error telling me that I'm missing some assembly (I've already refer it in References). 尝试在视图@model Components.Article设置模型的类型,我收到一条错误消息,告诉我我缺少某些程序集(我已经在参考中引用了它)。 Tried to use @using Components before the module - same result - CS0246: The type or namespace name 'Components' could not be found (are you missing a using directive or an assembly reference?) Any ideas how can I fix that? 试图在模块之​​前使用@using Components -结果相同CS0246: The type or namespace name 'Components' could not be found (are you missing a using directive or an assembly reference?)主意该如何解决?

Open the web.config file in your Views folder, and make sure it has the following: 打开“视图”文件夹中的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="Your.Namespace.Components" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>

当您向解决方案中添加文件夹并想通过@using引用它时,有时您需要再次构建解决方案,以使该错误消失,换句话说,您需要刷新解决方案文件夹。

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

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