2

Virtually every .aspx page I have in my web site needs to have this at its top to function correctly:

<%@ Assembly Name="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>

Is there anyway I can avoid having to declare this in the .aspx view for every page? Isn't there some way I can declare this globally for all .aspx views? Maybe something in the web.config?

4 Answers 4

4

Add it to assemblies

<assemblies>
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>

The @Assembly directive correspond to assemblies tag in web.config not namespace tag. Check MSDN reference

Sign up to request clarification or add additional context in comments.

1 Comment

It would be nice to know why it was down-voted so that whatever is incorrect can be corrected or improved :(
2

You can declare it in web.config in the assemblies section, like this:

<system.web>
   <compilation>
      <assemblies>
         <add assembly="System.Web.Mvc, Version=3.0.0.0 ... "/>        
      </assemblies>      
   </compilation>
</system.web>

However, according to the MSDN docs:

Assemblies that reside in your Web application's \Bin directory are automatically linked to ASP.NET files within that application. Such assemblies do not require the @ Assembly directive. You can disable this functionality by removing the following line from the section of your application's Web.config file:

<add assembly="*"/>

1 Comment

No, the @Assembly directive corresponds to the assembly config element
0

As others have pointed out, you can declare this in the web.config pages section.

Another alternative (if its available to you) is to use the new Razor View engine. It not only removes this type of code, but also provides cleaner, overall syntax. Of course, I realize this may not be a viable solution as you may be limited by your current technology/customer needs/etc.

An example of what you may see at the top of a Razor page is shown here:

@model Some.StronglyTyped.Model
@using Other.Libraries.To.Import
@{
    ViewBag.Title = "Specific Page Title";
}

1 Comment

It's nice, but it won't solve the assembly issue. (The way to do the assembly reference in Razor is to add the reference to the project).
-2

Put it in the Web.config as a global namespace. It will be available to all your pages there.

<system.web>
    <pages>
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />  
            </namespaces>
        </pages>
</system.web>

1 Comment

No, the @Assembly directive corresponds to the assembly config element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.