views:

518

answers:

3

Hi, I've searched over the topics on Stackoverflow but this question hasn't been answered so far.

I have two projects in my solution: a) MVC Application b) Class Library.

The class library acts as a plugin, so it contains views. The main problem is that I have no intellisense in the view's markup for my classes contained within the class library (the same assembly as the views).

In the beginning I couldn't even write <%= Html.RenderAction... %>. I've solved that by adding a Web.config file to the class library with the following section:

<configuration>
<system.web>
    <compilation debug="true">
        <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        </assemblies>
    </compilation>
</system.web>

Now it recognizes Html.RenderAction, etc in the view's markup. However I've no idea how to get access (with intellisense) to my classes contained within the same assembly as the views :(

Kind regards, Jakub

+1  A: 

There is a separate list of namespaces in the config where you need to include your custom namespaces. The example below demonstrates in the simplified web.config you add your namespaces. If this still does not work make sure that your project and webconfig has correct references to the other assembly.

<configuration>
    <pages>
        <namespaces>
            <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.Linq"/>
            <add namespace="System.Collections.Generic"/>
            <add namespace="Blog.Models"/> <!-- These are my custom namepaces -->
            <add namespace="Blog.Views"/>
        </namespaces>
    </pages>
</configuration>
smaclell
Thanks for the answer smaclell. I tried that already, but right-clicking on the class name doesn't work (no resolve namespace there).
Cosmo
No worries. I have not personally tried what you are doing but I can definitely see why you would want to split up your assemblies. Interesting that you still cannot see the classes even with assemblies lined up and namespaces in the web.config. Good luck.
smaclell
A: 

Out of the box, MVC does not support multiple projects. Check my previous questions for more detail.

No Refunds No Returns
I know, but I managed this using MEF and it's working perfectly. The only problem is intellisense for my own classes in the class library assembly. I could do it without intellisense, but that's not nice.
Cosmo
Thanks for the downvote.
No Refunds No Returns
A: 

The Spark viewengine as the same issue, see their documentation. Basically they say 'make a web app project' and treat it like a class library in every other way. Worked for me in Spark, maybe it'll work in your situation as well?

Erik van Brakel
Hi Erik, that would be an option, however I would like to get it working in a class library project :)
Cosmo
AFAIK the only real difference between a web app project and a class library is the GUID for the project type (which Visual Studio uses for determining which context to load). Correct me if I'm wrong, but there shouldn't be any negative side effects. If there are, I haven't encountered them yet ;-)
Erik van Brakel