Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i Use System.Web.UI.Page.ClientScript in ASp.Net MVC?

I am Trying to Register STart up Script in my ASP.Net MVC 3.0

I know I can use this syntax in VB.Net But not sure if i can use it in MVC

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

Intellisense is not picking up the properties for Page

like image 254
HaBo Avatar asked Oct 20 '11 16:10

HaBo


1 Answers

You do not have the Page object as a Web-Forms, but you can use ViewBag property on controller and write an script later write to your Views.

In your Controller

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

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

@Html.Raw(ViewBag.coInit)
like image 102
wnascimento Avatar answered Oct 12 '22 20:10

wnascimento