Whats the meaning of this syntax in Visual studio

2019-06-01 17:59发布

This question already has an answer here:

Does anyone know the meaning of the following 4 code snipets (or shortcuts, i don't know how to call them) in Visual Studio:

<%= variable %>
<%# variable %>
<%: variable %>
<%$ variable %>

I know the first one inserts a value into the page and the second one is used for data binding.

Are there any other similar shortcuts?

1条回答
\"骚年 ilove
2楼-- · 2019-06-01 18:46

The first one, <%= %> is called an inline expression, or a code render block. (http://msdn.microsoft.com/en-us/library/k6xeyd4z(v=vs.100).aspx)

The second one, <%# %> is called a data binding expression. (http://msdn.microsoft.com/en-us/library/bda9bbfx(v=vs.100).aspx)

The third one, <%: %> provides a way to automatically HTML encode the output of the code. I'm not sure what's it's called though so can't find you a documentation page on it, however there is a post on Scott Guthrie's blog: 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

The fourth one, <%$ %> is called expression builder syntax. (http://msdn.microsoft.com/en-us/library/d5bd1tad(v=vs.100).aspx)

查看更多
登录 后发表回答