ASP.NET MVC > Views - Razor Engine

Namespace in Razor view in ASP.NET MVC

How to import a namespace in razor view?


To import a namespace in Razor view, we use using statement as we write in C# class however it should be prefixed with @.

@using MVCTraining5.Utility 

Here we are importing namespace MVCTraining5.Utility namespace.

To call any method insider that namespace, we do not need to give a fully qualified name. Assuming LogError class is MVCTraining5.Utility namespace, we can call it's method like below. 

<p>@LogError.GetDate()</p> 

Assuming GetDate() method is declared in the LogError class that exists in the MVCTraining5.Utility namespace.

 Views: 3539 | Post Order: 19



Write for us