How Does <%: ... %> Differ From <%= ... %> in ASP.Net MVC
The <%= ... %> syntax has been available in ASP.NET since the platform was first invented. Just like the equivalent syntaxes in PHP, JSP, Classic ASP, and many other platforms, it’s a way to emit dynamic values into the HTML response. But this raises a question of security: if the dynamic value may originally have been supplied by a user, how can you be sure it doesn’t contain any unwanted HTML or malicious JavaScript? The standard way to avoid any such risk is to HTML-encode the value before emitting it, which converts any special characters (e.g., < ) to harmless HTML entities (e.g., < ) that the browser knows to treat as plain text. <%= Html.Encode(ViewData["greeting"]) %> The tricky bit is remembering to write Html.Encode() all the time, especially considering that sometimes you must not encode certain values because they may contain HTML that you do want (e.g., from HTML helper methods like Html.ActionLink() , which already take care of encoding an...