If condition in Razor view engine in ASP.NET MVC

How to perform if conditional operation in view?


@if (fileName == "itfunda")
 { 
 <p>The file name is not ITFunda</p>
} 
else
 { 
<p>Sorry, it is DotNetFunda</p>
 }
Notice that @ character is just before the first line of the conditional statement, else doesn’t have @ as the Razor markup automatically detects the starting and ending if block and assumes that else is the part of if not the HTML syntax. 

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