MVC 后台调用JS

示例控制器:

        public ActionResult Index()
        {
            ViewBag.js = "<script type='text/javascript'>alert('abc');</script>";
            return View();
        }

页面:

<html>
<head>
    <title>Demo</title>
</head>
<body>
    <div>
        @Html.Raw(ViewBag.js)
    </div>
</body>
</html>

就可以了

原文地址:https://www.cnblogs.com/hucaihao/p/3514143.html