There are two ways to add namespaces:
- Put
@using
namespace at the top of the page. - Put all the namespaces in Views\Web.config.
For example, if you want to use FunctionName(parameters) in your Razor view from the SiteHelper
\BasicHelper
class, you can pick any one from the above two ways:
#1
Add namespace at the top of the page:
@using myMvc3.SiteHelper
#2
This is so that you can get @Html.FunctionName(parameters)
to work without having to put @using
at the top of all pages. In your Views\Web.config file, you should add the following:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<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="myMvc3.SiteHelper"/>
</namespaces>
</pages>
</system.web.webPages.razor>