如何从控制器调用javascript函数。
问题描述:
我是MVC新手。我在asp.net中使用了一个函数,现在我想在MVC中实现它。我不知道如何从控制器调用它。我将感谢你的帮助。
我在asp.net中使用的功能如下:
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:
ClientScript.RegisterStartupScript(Page.GetType(), "OnLoad", "outerSvg();", true);
我想从控制器调用这个javascript函数,
感谢,
Usama Javed
I want to call this javascript function from controller,
Thankful,
Usama Javed
答
//从javascript函数中你可以获取如下的ViewData值
//from the javascript function you can take the ViewData value like below
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