Declare a variable in ASP.NET MVC

How to declare a variable in the View using Razor syntax?

To declare a variable in the View using Razor syntax, we need to first create a code block by using @{ and } and then we can use the same syntax we use in the C#.
@{
   var fileName = "dotnetfunda";
   var a = 20;
   var b = 30;
   var physicalPath = @"C:\program files";
   var doubleQuote = @"This is ""dotnetfunda.com""";
   string myName = "ITFunda";
   var sum = "60";
}
In the above code, notice that we have created the Code block and then start writing C# syntax to declare and assign the variables.

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 { ...