我已經四處查看,找不到解決方案,因此我在此找到自己的解決方案。從我讀過的東西,我將能夠使用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