i have an MVC 3 site using asp.net 4
in my views i have used <%=
for outputting data.
reading this post by phil haack -> http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx
He suggests that <%= should be a distant memory, as long as your using .net 4.
i have done a find and replace all, on on开发者_高级运维e of my views replacing
<%= to <%:
and everything works as normal.
so my question, can i go ahead and do a global replace on all my views? are there any issues to be aware of ?
Truegilly
Be careful though as if you have something like this:
<%= Html.Encode(Model.Foo) %>
you might get double encoding when you end up with:
<%: Html.Encode(Model.Foo) %>
Whereas the correct would be:
<%: Model.Foo %>
Personally I tend to always use:
<%= Html.DisplayFor(x => x.Foo) %>
So, it's not as easy as a simple search & replace. There might be some breaking modifications.
Everything that Darin said and this:
After-format with HTML
Be aware when you after format your output and add some HTML inside it as in
<%= this.Model.Explanation.Replace("\n", "<br/>") %>
This clearly won't work after you'd simply replace <%=
with <%:
.
精彩评论