How do I import a namespace in Razor View Page?

In this article, I have explained 2 methods to imports namespace in MVC’s razor view page

Method 1

@using SampleNamespace;
@Imports Mynamespace;

Method 2

Find "web.config" file in "Views" sections of your current project and add following code :

  <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <add namespace="System.Web.Mvc" />
      <add namespace="Samplenamespace.customer" />
<!-- add more namespace as above-->


Leave a Comment