1
votes

This may be a duplicate of some other question, but it's hard to search the web for <%: so I can't really find anything.

When I created a new Asp.net MVC 2 project its templates use the new notation of automatic html encoding. WHen I changed .net framework target to 3.5, these server scripts stopped working. When I changed them to <%= everything was fine, but it's not the same.

Anyway. Is it possible to take advantage of this notation and avoid writing tedious and long statements <%= Html.Encode(...) %>?

2

2 Answers

3
votes

Unfortunately it is not possible. It is mentioned in the following article. See the section titled Helpers now return an MvcHtmlString object. Also, see the explanation from Phil Haack as to why.

1
votes

As far as I know, this is an ASP.NET 4.0 only feature - so on 3.5, you still need to remember to use the Html.Encode(.....)..... another good reason to upgrade! :-)