C# MVC3视图找不到添加的引用类

C# MVC3视图找不到添加的引用类,c#,asp.net-mvc,asp.net-mvc-3,reference,C#,Asp.net Mvc,Asp.net Mvc 3,Reference,我的视图在查找位于我的一个引用中的类时遇到问题。 此引用是指在项目外部构建的dll 视图总是给出错误: 找不到类型或命名空间名称“Company”(是否为“”) 缺少using指令或程序集引用) 这是控制器。没有问题 using Company.Entities; public ActionResult Find() { Person test = Person.SelectByADDistinguishedName("L*", false); return View(test

我的视图在查找位于我的一个引用中的类时遇到问题。 此引用是指在项目外部构建的dll

视图总是给出错误:

找不到类型或命名空间名称“Company”(是否为“”) 缺少using指令或程序集引用)

这是控制器。没有问题

using Company.Entities;

public ActionResult Find()
{
    Person test = Person.SelectByADDistinguishedName("L*", false);
    return View(test);
}
这里是风景。错误出现在
@Model
行中

@model Company.Entities.Person

@{
    ViewBag.Title = "Bob";
}

<h2>Find</h2>
Files\root\49c9c7db\1f9dd5c8\App\u Web\u find.cshtml.a8d08dba.xro6gxci.0.cs 第27行

如果我删除了对程序集的任何提及(从web.config-no@using stations中删除)。我在加载时收到了相同的错误消息,但是针对这一行

public class _Page_Views_Home_Find_cshtml : System.Web.Mvc.WebViewPage<Company.Entities.Person> {
public class\u Page\u Views\u Home\u Find\u cshtml:System.Web.Mvc.WebViewPage{

请务必检查您的视图目录中是否有其他web.config文件。我似乎记得遇到过类似的问题,因为我没有更新正确的web.config.YMMV。

在使用它一段时间后,我最终解决了它

我必须将程序集添加到主web.config的assemblies部分下(而不是视图下的程序集)

web.config的示例

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="Company, Version=2.0.31.0, Culture=neutral, PublicKeyToken=df9010405db60e6d"/>
  </assemblies>
</compilation>

感谢给我建议的人。

添加参考资料

在使用控件之前,在.cshtml文件中可以工作。例如:

@model IEnumerable<MyApp.Models.MyModel>
@using System.Web.UI.WebControls;
@model IEnumerable
@使用System.Web.UI.WebControl;
但您可以将其放在web.config中的namespaces标记下。 这样,它对所有视图都是全局的。此外,无需指定版本:

<namespaces>
        <add namespace="System.Web.UI.WebControls" />
</namespaces>


Hi Hal,感谢您的快速响应,我已经添加了视图/web.config的内容。我已经在视图/web.config和/web.config中添加了名称空间,但没有成功。您是否尝试关闭视图并重新打开它?或者您在浏览视图时看到了死亡的黄色屏幕?编译不会因为视图中的语法错误而出错,是否确定视图中存在问题?错误仍然为-CS0246:找不到类型或命名空间名称“Dfait”(是否缺少using指令或程序集引用?)。向ticket添加了更多信息视图中不存在编译问题--错误指的是代码的哪一部分?出于某种原因,即使这对我也不起作用。这样一件基本的事情似乎不可能实现,这让我发疯。
@model IEnumerable<MyApp.Models.MyModel>
@using System.Web.UI.WebControls;
<namespaces>
        <add namespace="System.Web.UI.WebControls" />
</namespaces>