Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi,
I am new to MVC. There is a function i was using in asp.net, now i want to implement it in MVC. I dont know how to call it from controller. I shall be thankful for your help.
The function i was using in asp.net is as follow:

C#
ClientScript.RegisterStartupScript(Page.GetType(), "OnLoad", "outerSvg();", true);


I want to call this javascript function from controller,

Thankful,
Usama Javed
Posted
Comments
David_Wimbley 27-May-13 1:36am    
Why would you want to call client side code on the server side (I know about node.js)? This doesn't make much sense.

What is so special about this javascript function that it can't be done using MVC/JsonResult Action that you use as an Ajax call in your client side?

To me this seems like an unnecessary layer of complexity that is probably going to be the cause of many head aches for you.
osama.javed 27-May-13 3:11am    
I have a function drawsvg(x,y,value) in cshtml, and i want to pass these values to the javascript function to draw svg diagram.
Jameel VM 27-May-13 1:49am    
Don't compare ASP.NET Webform with ASP.NET MVC.Please post your scenario for calling Javascript inside the server side
osama.javed 27-May-13 3:10am    
I have a function drawsvg(x,y,value) in cshtml, and i want to pass these values to the javascript function to draw svg diagram.
Jameel VM 27-May-13 3:59am    
Store the values in to ViewData from the controller and take the viewData value from the javascript

1 solution

//from the javascript function you can take the ViewData value like below
C#
function YouJsFunction(){

var test = '@ViewData["NAME"].ToString()';

}


//Set the viewdata value befor returning view in the ActionResult
Public ActionResult YourAction()
{
ViewData["NAME"]="Hello";
return View();

}


Hope this helps
 
Share this answer
 
Comments
osama.javed 30-May-13 1:05am    
This is single value you are passing to the view. I want to pass an arraylist<object> to the view.. :)
Jameel VM 30-May-13 8:42am    
you can set array of objects in to the ViewData

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900