我环顾四周,找不到解决方案,因此我发现自己在这里。根据我的阅读,我可以使用 RegisterClientScript 或 RegisterClientScriptBlock 在 asp.net Web 表单中执行此操作。我在任何 MVC3 文档中都找不到这个。我在 MVC 3 视图中具有以下功能:
我的测试视图:
<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();
}
}