Updated on Kisan Patel
To write the variable data inside the string or URL, we wrap the variable with bracket.
@{string filename = "image"} <img src="https://www.dotnetfunda.com/images/@(fileName).jpg" />
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.
OR
To render a variable within a string, you could use string.Format
:
@{ var someVariable = "world"; } @string.Format("<div>hello {0}</div>", someVariable)