I am adding a control library reference from Infragistics to use their controls in my ASP .NET MVC 3 Razor views. I have added the dll as a reference to the project already.
My controllers can access the namespace fine if I add a using Infragistics.Web.Mvc
at the top of the file.
There are two ways to tell the views to include a namespace. The first is to put @using Infragistics.Web.Mvc
at the top of your view. However if I try that, I get the following error:
The type or namespace name 'Infragistics' could not be found (are you missing a using directive or an assembly reference?)
The second is to add a call to the namespace in the pages part of the view Web.config like this:
<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>
however this doesn't work either.
The only way I could get it to work was by adding the following line into the root Web.config file:
<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, I found that by including that line it tells the compiler to use that resource when compiling the ASP .NET resources. I had to use SN.exe to find the PublicKeyToken.
What am I doing wrong?
I'm not sure how the Infragistics installation works or how you're running your website, but you may need to tell Visual Studio to copy the dll on build so it's included with the web project. It's worth checking before exploring too many other options.
Here is an example
Looking at your code does not seems that you have put in the web.config the following:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
...
<add namespace="Infragistics.Web.Mvc" />
</namespaces>
</pages>
This tell your viewengine (razor or the others) to use also the infragistics dll as an extension.
If you are using Razor look also for the "namespace" tag inside View\web.config. You can specificy the namespace there if you prefer.
Hope it helps
Unfortunately you have something weird going on here - as the steps of simply adding the ref and including the namespace are enough to get this working.
In my apps, I have no entry in the assemblies element in the web.config and only a @using (for instance MVC grid @using MvcContrib.UI.Grid ) and everything works fine. I know that doesn't help much in resolving the issue but at least you know this 'should' work like this.
You also don't need the semicolon after your using statement. When you added the ref to that assembly which location did you add it from?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With