문제

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 one 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 <%:.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top