我添加了来自 Infragistics 的控件库引用,以便在我的 ASP .NET MVC 3 Razor View 中使用它们的控件。我已经添加了 dll 作为对该项目的引用。
如果我在文件顶部添加 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 项目中。在探索太多其他选项之前,值得检查一下。
这是一个例子
关于.net - 在 ASP.NET MVC 中添加对 View 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117114/