So I have a table in my view and with the help of the following script I send the ajax data to the controller which updates my database:
$('.save-table').on('click', function () {
var tr = $(this).parents('tr:first');
var PredefName = tr.find("#PredefName").val();
var PredefDescription = tr.find("#PredefDescription").val();
var PredefID = tr.find("#PredefID").html();
tr.find("#lblPredefName").text(PredefName);
tr.find("#lblPredefDescription").text(PredefDescription);
tr.find('.edit-mode, .display-mode').toggle();
$.ajax({
url: '/PredefinedViews/Update/',
data: JSON.stringify({ pID: PredefID, pName: PredefName, pDescript: PredefDescription }),
type: 'POST',
contentType: 'application/json; charset=utf-8',
error: function (event, jqxhr, settings, exception) {
alert("something went wrong")
if (jqxhr.status == 401) {
alert("session expired!");
}
},
success: function (event, jqxhr, settings, exception) {
alert("database updated!");
}
});
});
So I have a session that needs to be 5mins short which I set up successfully, I need the user to be notified that the session has expired BUT the error message never triggers after session has expired! it does however ALWAYS trigger the success message even if nothing has been saved to the database. So my question is, how do I trigger the ajax error?
EDIT1 Here is the method in my controller:
[HttpPost]
[ValidateInput(false)]
public ActionResult Update(int pID, string pName, string pDescript)
{
using (PanSenseEntities context = new PanSenseEntities())
{
tblPredefineView existingPredefineView = context.tblPredefineViews.Find(pID);
existingPredefineView.Name = pName;
existingPredefineView.Description = pDescript;
context.SaveChanges();
}
return Json(JsonRequestBehavior.AllowGet);
}
EDIT2 I just realized that if the session expires it doesn't even reach the controller! Im stumped here now...