Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <%: %> do in ASP.NET (MVC2)?

Tags:

asp.net

A coworker recently checked in a changeset where lots of expressions on the form <%= (...) %> were changed to <%: (...) %>.

I have a vague recollection of having heard what <%: does, but cannot remember. It's too late in the night to call my coworker, and Google and Bing both seem unable to search for the string "<%:".

Can someone enlighten me, please?

like image 468
Tor Haugen Avatar asked Jul 25 '10 23:07

Tor Haugen


1 Answers

It HtmlEncodes the string, if it hasn't already been encoded.

The "hasn't already been encoded part" is why MvcHtmlString was introduced. MVC2 returns MvcHtmlString from many HtmlHelper methods to represent strings that should not be re-encoded. The <%: %> knows not to re-encode.

See What is an MvcHtmlString and when should I use it? for a good discussion.

like image 188
Rob Avatar answered Oct 18 '22 09:10

Rob