我已经四处查看,找不到解决方案,因此我在此找到自己的解决方案。从我读过的东西,我将能够使用RegisterClientScript或RegisterClientScriptBlock在asp.net web窗体中执行此操作。我无法在任何MVC3文档中找到它。 我有一个MVC 3查看以下功能:如何从MVC3中的控制器调用javascript函数
MyTest的观点:
<div data-role="content">
<div id="mappingTable"></div>
</div>
</section>
@section Scripts {
<script type="text/javascript">
$("#jqm-home").live('pageinit', function() {
addTableRow(' adding data to table <br/>');
});
//I want to the able to call the function from the controller.
function addTableRow(msg) {
$('#mappingTable').append(msg);
};
</script>
}
在我的控制器我有以下。
public class MyTestController : Controller
{
#region Class Constractor
public MyTestController()
{
Common.ControllerResourceEvent += new System.EventHandler<ResourceEventArgs>(Common_ResourceEvent);
}
private void Common_ResourceEvent(object sender, ResourceEventArgs e)
{
//I want to call the function addTableRow and pass ResourceEventArgs
}
#endregion Class Constractor
public ActionResult Index()
{
return View();
}
}
你想让客户端调用服务器,反之亦然? – McGarnagle 2012-04-15 21:29:34
你想做什么?通过单击按钮调用服务器,然后调用客户端?为什么不只是使用AJAX调用服务器,然后在回调中可以调用你的函数。 – RPM1984 2012-04-15 21:32:43