私は ajax を使用していくつかの検証を行おうとしています。MVC3コントローラーからメソッドを呼び出しますが、コントローラーがtrueまたはfalseを返すかどうかにかかわらず、trueを返します。アラートは常に表示されます。
ClientChoices/HasJobInProgress
public Boolean HasJobInProgress(int clientId)
{
return false;
//return _proxy.GetJobInProgress(clientId);
}
Jquery.Ajax
$("#saveButton").click(function() {
var hasCurrentJob =
$.ajax({
url: '@Url.Action("HasJobInProgress", "ClientChoices")/',
data: { id: @Model.ClientId },
success: function(data){
return data;
}
});
if (hasCurrentJob) {
alert("The current clients has a job in progress. No changes can be saved until current job completes");
}
});
解決
$("#saveButton").click(function() {
$.ajax({
url: '@Url.Action("HasJobInProgress", "ClientChoices")/',
data: { id: '@Model.ClientId' },
success: function(data){
showMsg(data);
},
cache: false
});
});
function showMsg(hasCurrentJob) {
if (hasCurrentJob.toString()=="True") {
alert("The current clients has a job in progress. No changes can be saved until current job completes");
}
}