Ant*_*yrd 0 c# asp.net-mvc jquery
我从来没有使用过ajax,我只是试着看看它是否会从我的控制器调用该方法并给我想要的结果.VS中的javascript调试器目前似乎不起作用.这看起来不错吗?
$("form").submit(function() {
var hasCurrentJob = $.ajax({
url: 'Application/HasJobInProgess/@Model.ClientId'
});
});
Run Code Online (Sandbox Code Playgroud)
控制器方法
public Boolean HasJobInProgress(int clientId)
{
return _proxy.GetJobInProgress(clientId).Equals(0);
}
Run Code Online (Sandbox Code Playgroud)
更新
$("#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");
}
});
Run Code Online (Sandbox Code Playgroud)
Url.Action在调用action方法时尝试使用HTML Helper方法.这将为您提供action方法的正确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);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67 次 |
| 最近记录: |