Updated on Kisan Patel
To import a namespace in Razor markup, we use using statement as we write in C# class however it should be
prefixed with @.
@using MVC.Utility
To call any method insider that namespace, we do not need to give a fully qualified name. Assuming LogError
class is in this namespace, we can call its method like below.
<p>@LogError.GetDate()</p>
Here we are importing namespace MVC.Utility namespace.
OR
You could also specify namespace in web.config file then you don’t need to import namespace in razor view.
web.config
<system.web.webPages.razor> ... <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> .... <add namespace="MVC.Utility" /> </namespaces> </pages> </system.web.webPages.razor>