MVC by default outputs a string as plain string, not HTML.
e.g. in your Action
:
public ActionResult Test()
{
var model = new TestViewModel(); // your view model
model.Message = "<b>hello</b>";
return View(model);
}
your View
:
@model MyProject.TestViewModel
<div>
@Model.Message
</div>
This will render as:
<b>hello</b>
If you want to actually render it as HTML, you need to change the above to this:
@MvcHtmlString.Create(Model.Message)
Alternatively, you could create an extension to make it nicer:
public static MvcHtmlString ToMvcHtmlString(this String str)
{
if (string.IsNullOrEmpty(str))
return MvcHtmlString.Empty;
else
return MvcHtmlString.Create(str);
}
So then to render a string as HTML, in your View
, you could write:
@Model.Message.ToMvcHtmlString()
If this is not what you're after, you should provide us with an example of where your code is falling over.