variable data inside URL in ASP.NET MVC

How to write variable data inside the URL?

To write the variable data inside the URL, we wrap the variable with bracket. 
<img src="http://www.dotnetfunda.com/images/@(fileName).gif" /> 
Here, we are assuming that fileName is the name of variable declared somewhere at the top.
Notice that the variable filename is wrapped with “(“ and “)”, if we do not do that Razor doesn’t understand fileName as a variable and throws error. 
 CS1061: 'string' does not contain a definition for 'gif' and no extension method 'gif' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) 

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