Adding a reference to a view in ASP.NET MVC

19,924

Solution 1

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

enter image description here

Solution 2

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

Solution 3

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?

Share:
19,924
dnatoli
Author by

dnatoli

I am currently working as a Software Engineer for Redbubble.com.

Updated on June 04, 2022

Comments

  • dnatoli
    dnatoli almost 2 years

    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.

    reference
    reference properties

    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?

  • dnatoli
    dnatoli over 12 years
    I added it from a folder in Program Files on my local machine.
  • dnatoli
    dnatoli over 12 years
    If I use "@using Infragistics.Web.Mvc" in the view file, I don't need to include the namespace call in Web.config. Putting the namespace in makes it available in all views. However, neither putting the namespace in or "@using" will work without the assembly call in my case.
  • Iridio
    Iridio over 12 years
    If also this don't work maybe a corrupt installation of infragistcs?
  • dnatoli
    dnatoli over 12 years
    That was it! Set Copy Local to true and removed the compile tags and it worked. :D
  • Shumii
    Shumii over 10 years
    Worked for me too. But you only get a particular list of controls available. How do you go about using the WebDropDown control?
  • NoWar
    NoWar over 10 years
    Good catch, bro! Thanks!
  • Ambrose Little
    Ambrose Little about 10 years
    Here's more info on getting started with Infragistics ASP.NET MVC helpers: help.infragistics.com/Doc/jQuery/Current/…