.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>&lt;unknow man&gt;</p> <p>&amp;lt;unknow man&amp;gt;</p> 

in chrome:

<p>​<unknow man>​</p> ​<p>​&lt;unknow man&gt;</p>​ 

and incredible (for me) have same visual output:

<unknow man>  &lt;unknow man&gt;  

i wanted display, however, 1 in html:

<p>&lt;unknow man&gt;</p> <p>&lt;unknow man&gt;</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("&lt;unknow man&gt;") : @model.clientname)</p> <p>     @if (@model == null)     {         <text>&lt;unknow man&gt;</text>     }     else     {           @model.clientname;     } </p> 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -