c# - MvcHtmlString.ToString is escaping the text in Razor -


i want change displayfor output (format string), output string has ampersand. how can handle mvchtmlstring not escape ampersand?

this code in cshtml file:

@{     string title = @html.displayfor(model => model.entity.description).tostring();     if (model.city != null)         title = string.format("{0} em {1}", title, model.entity.cityname);     viewbag.title = title; } 

the model.entity.description has value "automóvel" in database. output rendered in html automóvel. here html output:

<p>autom&amp;#243;vel</p> 

if try use html.raw() in viewbag.title, title not shown.

edit: added more details

even if try suggested approach of using code, viewbag.title not display it. here modified code after comments:

@{     string title = model.entity.description;     if (model.city != null)     {          title = string.format("{0} em {1}", model.entity.description,             model.entity.cityname);     }     viewbag.title = html.raw(httputility.htmldecode(title)); } 

you don't need interfere title in way, assign directly:

viewbag.title = model.entity.description; 

Comments