나는 둥근 모양을하고 해결책을 찾을 수 없으므로 여기에서 자신을 찾는다. 내가 읽은 것부터 asp.net 웹 폼에서 RegisterClientScript 또는 RegisterClientScriptBlock을 사용하여이 작업을 수행 할 수있었습니다. 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
당신은 무엇을하려고합니까? 버튼 클릭으로 서버를 호출하면 클라이언트가 호출됩니다. AJAX를 사용하여 서버를 호출하는 것이 아니라 콜백에서 함수를 호출 할 수 있습니다. – RPM1984