views:

116

answers:

2

I have a Class Library project and MVC project in the one solution.

My class library has the namespace MyStuff.Classes

My MVC project has the namespace MyStuff.Web

I can't seem to access my class library from the mvc project or vice versa directly or with a using directive??

Whats the best way to use namespaces in this instances? and in general? any hints tips welcome.

Thanks

+3  A: 

You need to add a reference to your Class project

If you right click on references in your MVC project hit the Projects tab to easily add a reference to your Class project.

Martijn Laarman
Thanks, so I obvious I never thought of it!
Rigobert Song
+1  A: 

It depends on where in your MVC project you want to access this class library. First you need to add a project reference to the class library. Accessing it from the Model or the Controller should be trivial.

In order to access it in the view you need to add the following to your web.config:

<pages>
  <namespaces>
    <add namespace="MyStuff.Classes"/>
  </namespaces>
</pages>

Then you can strongly type your view:

<%@ Page Language="C#" 
         MasterPageFile="~/Views/Shared/Site.Master" 
         Inherits="System.Web.Mvc.ViewPage<MyStuff.Classes.MyClass>" %>
Darin Dimitrov