.net - 在 ASP.NET MVC 中添加对 View 的引用

标签 .net asp.net-mvc asp.net-mvc-3 razor

我添加了来自 Infragistics 的控件库引用,以便在我的 ASP .NET MVC 3 Razor View 中使用它们的控件。我已经添加了 dll 作为对该项目的引用。

reference
reference properties

如果我在文件顶部添加 using Infragistics.Web.Mvc ,我的 Controller 可以正常访问命名空间。

有两种方法可以告诉 View 包含命名空间。第一个是将 @using Infragistics.Web.Mvc 放在 View 的顶部。但是,如果我尝试这样做,则会收到以下错误:

The type or namespace name 'Infragistics' could not be found (are you missing a using directive or an assembly reference?)

第二个是在 View Web.config 的页面部分中添加对命名空间的调用,如下所示:

<system.web.webPages.razor>
   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ABCABCABCABCABC" />
   <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
         Other namespaces...
         <add namespace="Infragistics.Web.Mvc"/>
      </namespaces>
   </pages>
</system.web.webPages.razor>

但是这也不起作用。

我可以让它工作的唯一方法是将以下行添加到根 Web.config 文件中:

<system.web>
   <compilation debug="true" targetFramework="4.0">
      <assemblies>
         ...
         <add assembly="Infragistics.Web.Mvc, Version=3.11.1.2010, Culture=neutral, PublicKeyToken=blahblahblah" />
      </assemblies>
   </compilation>

On some further investigation regarding Web.config ,我发现通过包含该行,它会告诉编译器在编译 ASP .NET 资源时使用该资源。我必须使用 SN.exe 来查找 PublicKeyToken。

我做错了什么?

最佳答案

我不确定 Infragistics 安装如何工作或如何运行网站,但您可能需要告诉 Visual Studio 在构建时复制 dll,以便将其包含在 Web 项目中。在探索太多其他选项之前,值得检查一下。

这是一个例子

enter image description here

关于.net - 在 ASP.NET MVC 中添加对 View 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117114/

相关文章:

c# - http ://ifconfig. me 如何从客户端获取所有这些信息?

c# - 什么是 nAnt,它如何对我作为 C# 开发人员有用?

c# - 使用 SendKeys.sendwait() 发送 "spacebar key"

c# - 检测到 ASP.NET MVC 5 危险的 Request.Path

asp.net-mvc - Web API 模型绑定(bind)与 Multipart formdata

c# - EntityFramework 在 App.config 中看不到 ConnectionString

asp.net-mvc-3 - 从 Razor View-MVC3 ASP.NET 中的 Web.config 访问键值

c# - 使用 System.Runtime.Caching,但是当我去检索它时,它是空的?

c# - 字典中键的多个选项?

asp.net-mvc - Asp.net - MVC1 与 MVC2