Dmitry Borovsky
Dmitry Borovsky

Reputation: 558

Should we use encoding for HtmlString?

What's better in ASP.NET MVC

<%= Html.LabelForModel() %>

or

<%: Html.LabelForModel() %>

? Why?

Upvotes: 4

Views: 677

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1062580

If it returns MvcHtmlString it won't matter; the <%: will know it is pre-escaped. I would therefore use <%: as then the reviewer doesn't need to think "is this escaped? or is this a raw field?".

Of course, that does depend on the code that creates the MvcHtmlString being sane...

Upvotes: 5

John Farrell
John Farrell

Reputation: 24754

Neither is "better". They both output the same exact markup.

Upvotes: 0

Related Questions