I've found several answers including this one and also this one. But for some reason this.Response.IsClientConnected
still goes as true
.
Here is my Client:
<div class="ajax-loader-gif-close" id="cancelBusy">Close</div>
@using (Html.BeginForm("List", "Visit", FormMethod.Post, new { @id = "formFilter" }))
{
//Some models some TextBoxFor etc.
}
<script type="text/javascript" language="javascript">
var ajaxCallObject = null;
$(document).ready(function () {
$('form').submit(function () {
ajaxCallObject = $.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
beforeSend: function () {
toggleBusyIndicator();
},
complete: function () {
toggleBusyIndicator();
},
success: function (result) {
//Some stuff
}
});
return false;
});
}
$("#cancelBusy").click(function () {
ajaxCallObject.abort();
});
});
</script>
Here is my Server-Side:
[HttpPost]
public PartialViewResult List(VisitFilterViewModel model)
{
//IsClientConnected is ALWAYS TRUE even though I abort from client
while (this.Response.IsClientConnected)
{
Thread.Sleep(500);
}
return PartialView("PartialVisitFilterList", model);
}
With FireBug I see that the action is Aborted, but IsClientConnected
is still true
. What am I doing wrong?
Note: If you consider removing [HttpPost]
attribute to solve this, I've already tried and didn't work.
Thanks to this post I finally solved it! Actually, what I did was completely working but since I was running this in my local computer with VS Development, the Response was never ended. But, when I put it on IIS Server, everything worked out just fine.
In case site or the post is deleted, I'm posting the answer here: