This is what worked for me. Here is my HomeController code:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new HomeModel();
model.Name1 = "Márcia";
model.Name2 = "Márcia";
return View(model);
}
}
Here is my Home Index view:
@model mvctestappweb.Models.HomeModel
@{
ViewBag.Title = "Index";
}
@Model.Name1
<br />
@Html.Raw(Model.Name2)
The output on the view looks like this:
Márcia
Márcia
EDIT: I see. The issue is that as soon as you put the RAW into the HTML <span> tag that it converts the á to á 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:
(I know this isnt ideal, but it was the best work around I could find.)
My controller code:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new HomeModel();
model.Name = "Márcia";
model.SpanHtml = "<span title='Márcia'>Márcia</span>";
return View(model);
}
}
Here my view:
@model mvctestappweb.Models.HomeModel
@{
ViewBag.Title = "Index";
}
1: @Html.Raw("<span title=\"" + @Html.Raw(Model.Name) + "\">" + @Model.Name + "</span>")
<br />
2: @Html.Raw(@Model.SpanHtml)
The output on the view looks like this:
1: Márcia
2: Márcia
My HTML source looks like this:
1: <span title="Márcia">Márcia</span>
<br />
2: <span title='Márcia'>Márcia</span>
@HttpUtility.HtmlDecode(Html.DisplayFor(model => model.Name).ToString())and let me know the result.