开发者

Asp.net MVC difference between <%: and <%= [duplicate]

This question already has answers here: What is the difference between <%: and <%= in ASP.NET MVC? (3 answers) 开发者_JAVA百科 Closed 9 years ago.

Can somebody explain me the difference between using <%: and <%= in an aspx view of an MVC application.

Thanks, Radu


Roughly speaking, <%=term%> translates to Resonse.Write(term) whereas <%:term%> translates to Response.Write(Html.Encode(term))


<%: does an HTML Encode, whereas <%= does not.


It automatically html encodes the text that is rendered in the webpage.


<%: %> will attempt to convert whatever is placed in between it to a string then Html Encodes it and outputs it to the response stream.. However, if the object implements IHtmlString, it will NOT encode it.

<%= %> will convert whatever is between it to a string and output it to the response stream.


The <%: was a new syntax that came with ASP.NET 4.0 and in effect it automatically HtmlEncodes the contents contained within the tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜