Robert Koritnik
Robert Koritnik

Reputation: 105039

Globally add "<@Assembly>" and "<@Import Namespace>" to Asp.net MVC views

Instead of writing

<@ Import Namespace="Microsoft.SharePoint" %>

on every view I create I know I can easily just edit my web.config file and add this:

...
<pages>
    <namespaces>
        <add namespace="Microsoft.SharePoint" />
    </namespaces>
</pages>

But this doesn't seem to work in design time. Visual Studio 2010 is not able to see SPContext unless I add these two lines on top of my view as well:

<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>

So how do I add assemblies globally as well as import namespaces so VS will be able to resolve classes/objects?

Upvotes: 5

Views: 3457

Answers (2)

Kev
Kev

Reputation: 119816

You also need to add the assembly to the <assemblies> section of the <compilation> section under <system.web>:

<compilation debug="false" targetFramework="4.0">
  <assemblies>
    <add 
      assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  </assemblies>
</compilation>

Your targetFramework and debug attribute values may vary according to the framework version you're targetting and whether you're debugging or not.

Upvotes: 5

Andrew Barber
Andrew Barber

Reputation: 40150

It should work if you add the assembly in the Web.config, too.

Upvotes: 2

Related Questions