gpt4 book ai didi

asp.net-mvc-3 - 我可以在 ASp.Net MVC 中使用 System.Web.UI.Page.ClientScript 吗?

转载 作者:行者123 更新时间:2023-12-04 07:37:25 26 4
gpt4 key购买 nike

我正在尝试在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com