I am writing an MVC3 application and on one of the pages I bring back a list of items that are displayed in a table with paging and sorting.
However, I want to put up a message telling the user to refine their search further if the records bought back are over a certain number.
I have implemented this by changing the Response.StatusCode
in my controller, if the above condition is met;
public PartialViewResult VerbatimGridUpdate(VerbatimFormModel model)
{
if (ModelState.IsValid)
{
var mod = ModelBuilder.GetVerbatimFormModel(model);
if (mod.Verbatims.Count() > 10000)
{
HttpContext.Response.StatusCode = 33;
}
return PartialView("_VerbatimGrid", mod);
}
else
{
return PartialView(model.Verbatims);
}
}
And in my markup I capture this failure using the OnFailure event of the Ajax form;
function FailureLoading(ajaxContext) {
if (ajaxContext.status == "33") {
var ul = $("#validationSummary ul");
$("ul").empty();
ul.append("<li>" + "Too many records returned, please refine your search." + "</li>");
}
}
</script>
<div class="filters" >
@using (Ajax.BeginForm("VerbatimGridUpdate", null, new AjaxOptions { HttpMethod= "Get", UpdateTargetId = "grid-container", OnBegin = "StartLoading", OnSuccess = "FinishLoading", OnFailure="FailureLoading"}, new { id = "VerbatimListForm", name="VerbatimListForm" }))
{
everything works fine locally but as soon as I deploy to our UAT server, the failure event isn't fired and all the records are displayed. I can't work out why I am getting this difference in behaviour. Any ideas will be most welcomed. Thank you.