MVC2 as <%: tag is different from <% =

what is the difference between <%: and <% =?

+3
source share
2 answers

The difference is that <%: automatically HTML encodes the string, while <% = not.

Back before MVC2 comes out, so that HTML encodes the string that you should have used in the presentation of the Html.Encode () method.

<%= Html.Encode(Model.MyString) %>

However, with MVC2 they added the <%: tag, which outputs the same, but handles the HTML encoding for you.

<%: Model.MyString %>

As a rule of thumb, you should always output your lines using the <%: tag, unless you have a good reason.

.

ASP.NET 4 (<%:% > ) , , <% =% > do - HTML . HTML ...

+5

, <%: , . :

<%: Model.Title %>

... - , :

<%= Server.HtmlEncode(Model.Title ) %>

, :

<%: Html.TextBoxFor(Model => Model.Title) %>

... , :

<%= Html.TextBoxFor(Model => Model.Title) %>

. 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.

+3

Source: https://habr.com/ru/post/1769176/