controller:

            StringBuilder s = new StringBuilder();
            string a = "<script>alert('我StringBuilder')</script>文档内容";
            s.AppendFormat("<h1>{0}</h1><h1>测试</h1>", a);
            string t=s.ToString();
            ViewBag.newMes = t;

cshtml:

    <div id="haha"></div>
<script type="text/javascript">
    $(document).ready(function () {
        var newMes = '@Ajax.JavaScriptStringEncode(ViewBag.newMes)';
        document.getElementById("haha").innerHTML =newMes;
    });
</script>

 

posted on 2016-11-27 17:34  jinzhaoyoujiu  阅读(546)  评论(0编辑  收藏  举报