I’m new in ASP.NET C# and I have problems with some things.
In PHP, I can store HTML code inside a variable, for example:
$list = "<li>My List</li>";
echo "<ul>{$list}</ul>"; // write <ul><li>My List</li></ul>
I tried this in ASP.NET and Razor
string List = "<li>My List</li>";
<ul>@List</ul>
But ASP changes “<” and “>” to > and <.. You know any solution for this?
I have another question, can I insert variable inside a quotes like PHP?
echo "<ul>{$list}</ul>";
The Razor engine HTML encodes strings by default, as you have noticed. To avoid this behavior, just use
Html.Raw():Edit
To render a variable within a string, I suppose you could use
string.Format:Although that seems like overkill (at least for this example) when you can just write: