Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what worked for me. Here is my <code>HomeController</code> code:</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { var model = new HomeModel(); model.Name1 = "Márcia"; model.Name2 = "M&amp;#225;rcia"; return View(model); } } </code></pre> <p>Here is my Home Index view:</p> <pre><code>@model mvctestappweb.Models.HomeModel @{ ViewBag.Title = "Index"; } @Model.Name1 &lt;br /&gt; @Html.Raw(Model.Name2) </code></pre> <p>The output on the view looks like this:</p> <pre><code>Márcia Márcia </code></pre> <hr> <p><strong>EDIT</strong>: I see. The issue is that as soon as you put the RAW into the HTML <code>&lt;span&gt;</code> tag that it converts the á to <code>&amp;#225;</code> no matter what. I played with this a good bit and was unable to find a way to stop this from happening. So, here are two work arounds that might work for you:</p> <p>(I know this isnt ideal, but it was the best work around I could find.)</p> <p>My controller code:</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { var model = new HomeModel(); model.Name = "Márcia"; model.SpanHtml = "&lt;span title='Márcia'&gt;Márcia&lt;/span&gt;"; return View(model); } } </code></pre> <p>Here my view:</p> <pre><code>@model mvctestappweb.Models.HomeModel @{ ViewBag.Title = "Index"; } 1: @Html.Raw("&lt;span title=\"" + @Html.Raw(Model.Name) + "\"&gt;" + @Model.Name + "&lt;/span&gt;") &lt;br /&gt; 2: @Html.Raw(@Model.SpanHtml) </code></pre> <p>The output on the view looks like this:</p> <pre><code>1: Márcia 2: Márcia </code></pre> <p>My HTML source looks like this: </p> <p></p> <pre><code>1: &lt;span title="Márcia"&gt;Márcia&lt;/span&gt; &lt;br /&gt; 2: &lt;span title='Márcia'&gt;Márcia&lt;/span&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload