如何从控制器调用javascript函数。 [英] How to call a javascript function from controller.

查看:133
本文介绍了如何从控制器调用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


这篇关于如何从控制器调用javascript函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆