我正在将模型发送到具有字符串的视图。这些字符串是 html 编码的,我不需要它们。有什么方法可以在没有 html 编码的情况下将模型发送到视图?
模型:
public class Package
{
public string String { get; set; }
}
控制器:
public ActionResult GetPackage()
{
Package oPackage = new Package();
oPackage.String = "using lots of \" and ' in this string";
return View(oPackage);
}
看法:
@model Models.Package
<script type="text/javascript">
(function () {
// Here @Model.String has lots of ' and "
var String = "@Model.String".replace(/'/g, "'").replace(/"/g, "\"");
// Here String looks ok because I run the two replace functions. But it is possible to just get the string clean into the view?
})();
</script>
运行替换函数是一种解决方案,但只获取没有编码的字符串会很棒。