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.

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...