Click here to Skip to main content
13,554,621 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 17 Sep 2011
Licenced CPOL

Add namespaces for Razor pages

, 18 Sep 2011
Rate this:
Please Sign up or sign in to vote.
How to add namespaces for Razor pages

There are two ways to add namespaces:

  1. Put @using namespace at the top of the page.
  2. 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:


Add namespace at the top of the page:

@using myMvc3.SiteHelper


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:

  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, 
                        Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.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="myMvc3.SiteHelper"/>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Monjurul Habib
Software Developer (Senior)
Singapore Singapore
A life-long-learner, maker and soft music fan. Likes building things to solve problems. Years of successful records serving mid and large scale .NET applications in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture.

Always looks for new technology and loves to get hands dirty Smile | :)

You may also be interested in...

Comments and Discussions

Generalokye Pin
sonusharmaji18-Jan-12 3:00
membersonusharmaji18-Jan-12 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 18 Sep 2011
Article Copyright 2011 by Monjurul Habib
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid