tags:

views:

9

answers:

1

In the past I have always worked from the code behind page in ASP.NET and emitting all of my markup from that area.

I am now learning MVC and am working in the .ASPX page directly.

The following statements can be written...

<%= Html.Label("Test") %>
<%: Html.Label("Test")%>
<% Html.Label("Test"); %>

The first two emit the word 'Test', while the 3rd doesn't do anything. Yet no errors are thrown.

I seem to recall <%= is shorthand for <% Response.Write("") %>. Is <%: the same shortcut?

I suppose the 3rd statment runs, but simply returns a string that is discarded.

+1  A: 

You are right about 1 and 3. 2 does as one, but it html escapes the output.

klausbyskov
Thanks for the help.What do you mean by it 'escapes the output'? I just looked at the HTML emitted by 1 and 2 and it appears to be identical to me.
John
@John, check here for an indepth discussion: 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
klausbyskov