Can I use System.Web.UI.Page.ClientScript in ASp.Net MVC?

I am trying to register START Script in my ASP.Net MVC 3.0

I know that I can use this syntax in VB.Net, but I'm not sure if I can use it in MVC

System.Web.UI.Page.ClientScript.RegisterStartupScript(typeof(Page), "co", "coInit(0, 'R');", true); 

Intellisense does not collect properties for the page

+6
source share
1 answer

You don't have a Page object like Web-Forms, but you can use the ViewBag property on the controller and write a script later to write to your views.

In your controller

 ViewBag.coInit = "<script type="text/javascript">coInit(0, 'R');</script>" 

In your view (if you are using MVC3, use Raw helper for wirte javascript without encoding.)

 @Html.Raw(ViewBag.coInit) 
+3
source

Source: https://habr.com/ru/post/899715/


All Articles