views:

127

answers:

3

I can't find this info anywhere. Probably because Google is ignoring the keywords. Is there a difference between using <%: and <%= in your asp? They seem interchangeable.

+11  A: 

<%: %> is a new thing in MVC 2.

It is the same as <%= Html.Encode("Text") %>.

See more details here: http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx

Current recommendation is to always use <%: %> unless you have some specific reason to not do so (for example, you are rendering data from some file or database that's already been encoded).

ntcolonel
Awesome thanks, exactly what I was looking for.
Chris
A: 

The difference is :

<%= "my <text>" %> will output my <text>, which is incorrect HTML

<%: "my <text>" %> will output my &lt;text&gt;, which is better

More details here

Shtong
+4  A: 

@ntcolonel is right on the money. Additionally, for cases where your data has already been encoded, provide it using anything implementing IHtmlString. This prevents double-encoding, and allows you to always use <%: %>.

I believe that ASP.NET 4 shops should gravitate toward enforcing <%: %> by policy.

Also, the new syntax is for ASP.NET 4 in general; not necessarily just MVC, which is great news for WebForms developers.

kbrimington