Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET MVC, what is the difference between <%= and <%:?

I'm new to ASP.NET MVC. I've seen both <%= ... %> and <%: ... %>. I'm familiar with the first from classic ASP days, but not the latter. What is the difference between the two?

like image 750
John Mills Avatar asked Dec 05 '22 02:12

John Mills


1 Answers

<%= %> - equivalent to response.write in classic ASP.

<% %> - represents a code block, if, then else, for each, etc.

<%: %> - this is a shortcut new to .NET 4, this represents <%= html.encode(item) %>

Link to video explaining the shortcut (it's a short clip):

like image 156
Tommy Avatar answered Dec 28 '22 00:12

Tommy