This project is read-only.

Add a namespace in all Razor views in a module

Topics: Writing modules
Feb 5, 2013 at 6:21 PM
I'm using Orchard 1.6 and would like to move the using directives from the Razor views to the Views folder web.config. This is a custom module. The syntax is described here - - but I can't get it to work (the views can't find the classes).
Feb 5, 2013 at 6:53 PM
Are you doing this in the web.config of your module, or of the Orchard.Web project?
Feb 6, 2013 at 10:08 AM
There is a separate web.config in the Views folder of my module, which looks like the perfect place to do this.
Feb 6, 2013 at 1:09 PM
Are you saying that's where you tried it? Why not try Orchard.Web\web.config and see if it works?
Feb 6, 2013 at 1:22 PM
Because I want a specific namespace to be available in a single module views.
Feb 6, 2013 at 1:56 PM
Edited Feb 6, 2013 at 1:57 PM
Right, makes sense, my mistake.

I've done what you're asking by editing the web.config of my module in two places. In my case I was adding the System.Transactions namespace to be available in my module's Razor views:
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
        <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="Orchard.Mvc.Html" />
        <add namespace="System.Transactions" />
    <compilation targetFramework="4.0">
        <add assembly="System.Web.Abstractions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.Helpers, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.WebPages, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
       <add assembly="System.Transactions, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Feb 6, 2013 at 2:09 PM
Great, works for me.

Thanks Your Highness ;)