public class SampleViewModel
{
public string SampleString { get; set; }
public MvcHtmlString SampleHtmlString { get; set; }
}
对于Core 1.0+(和MVC 5+)使用HtmlString
public class SampleViewModel
{
public string SampleString { get; set; }
public HtmlString SampleHtmlString { get; set; }
}
然后
<!-- this will be encoded -->
<div>@Model.SampleString</div>
<!-- this will not be encoded -->
<div>@Html.Raw(Model.SampleString)</div>
<!-- this will not be encoded either -->
<div>@Model.SampleHtmlString</div>