.net - using Html.Encode in Razor -
i have following sample code in razor view on mvc4 sample project:
<p>@((@model == null) ? "<unknow man>" : @model.clientname)</p> <p> @if (@model == null) { @html.encode("<unknow man>") } else { @model.clientname; } </p>
the output little bit odd me...
in internet explorer see:
<p><unknow man></p> <p>&lt;unknow man&gt;</p>
in chrome:
<p><unknow man></p> <p><unknow man></p>
and incredible (for me) have same visual output:
<unknow man> <unknow man>
i wanted display, however, 1 in html:
<p><unknow man></p> <p><unknow man></p>
and 1 user:
<unknow man> <unknow man>
ps
i found solution, finally, display string, this
@if (@model == null) { @("<unknow man>") }
but can explain me difference html.encode in browsers, , why didn't work coded in first example?
<p>@((@model == null) ? @html.raw("<unknow man>") : @model.clientname)</p> <p> @if (@model == null) { <text><unknow man></text> } else { @model.clientname; } </p>
Comments
Post a Comment