How to add / import namespace to Razor View in MVC 3

There are two methods in which you can add a namespace to a Razor view in ASP.NET MVC 3.

Method 1
The first way is to use the @using statement in .cshtml files, which imports a namespace to the current file only.

Example :-
[sourcecode language=”csharp”]
@using Namespace1
@using Namespace2.SomeClass

Method 2
and the second way is to define these namespaces in the web.config of the View directory of your project.

[sourcecode language=”xml”]
 <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” />
 <! — can more more here… →

or you can add your custom namespace like this too :
[sourcecode language=”xml”]
<add namespace=”Custom.Yasser” />
<add namespace=”Custom.Mohsin” />