私は見た目が丸いので解決策を見つけることができません。私が読んだことから、私はasp.net WebフォームでこれをRegisterClientScriptまたはRegisterClientScriptBlockを使って行うことができました。私はMVC3のドキュメントでこれを見つけることができません。私は次のことを持っている私のコントローラでMVC3のコントローラからjavascript関数を呼び出す方法
<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>
}
:
のMyTestビュー: 私はMVC 3ビューで、以下の機能を持っています。
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
あなたは何をしようとしていますか?ボタンのクリックでサーバーを呼び出すと、クライアントが呼び出されます。なぜAJAXを使ってサーバを呼び出すのではなく、コールバックであなたの関数を呼び出すことができます。 – RPM1984