我正在尝试在我的 ASP.Net MVC 3.0 中注册启动脚本
我知道我可以在 VB.Net 中使用这种语法
但不确定我是否可以在 MVC 中使用它
System.Web.UI.Page.ClientScript.RegisterStartupScript(typeof(Page), "co", "coInit(0, 'R');", true);
Intellisense 未获取 Page 的属性
最佳答案
您没有作为 Web 窗体的 Page 对象,但您可以在 Controller 上使用 ViewBag 属性,然后编写脚本写入您的 View 。
在您的 Controller 中
ViewBag.coInit = "<script type="text/javascript">coInit(0, 'R');</script>"
在您的 View 中(如果您使用 MVC3,请使用 Raw helper 来编写没有编码的 javascript。)
@Html.Raw(ViewBag.coInit)
关于asp.net-mvc-3 - 我可以在 ASp.Net MVC 中使用 System.Web.UI.Page.ClientScript 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839163/