0

我从来没有使用过ajax,我只是想看看这是否会从我的控制器调用该方法并给我想要的结果。VS 中的 javascript 调试器目前似乎无法正常工作。这看起来对吗?

 $("form").submit(function() {
            var hasCurrentJob = $.ajax({
                url: 'Application/HasJobInProgess/@Model.ClientId'
            });
  });

控制器方法

public Boolean HasJobInProgress(int clientId)
{
    return _proxy.GetJobInProgress(clientId).Equals(0);
}

更新

$("#saveButton").click(function() {
        var hasCurrentJob = false;
        $.ajax({
            url: '@Url.Action("HasJobInProgress","ClientChoices")/',
            data: { id: @Model.ClientId },
            success: function(data){
                hasCurrentJob = data;
            }
            });
        if (hasCurrentJob) {
            alert("The current clients has a job in progress. No changes can be saved until current job completes");
        } 
    });
4

1 回答 1

5

Url.Action在调用操作方法时尝试使用HTML Helper 方法。这将为您提供操作方法的正确 URL。您无需担心要添加多少 ..//

$(function(){
   $("form").submit(function() {
     $.ajax({
        url: '@Url.Action("HasJobInProgess","Application")',
        data: {clientId: '@Model.ClientId'},
       success: function(data) {
        //you have your result from action method here in data variable. do whatever you want with that.
        alert(data);
       }
     });
   });
});
于 2012-04-09T20:48:32.177 回答