I have this call which calls a action in the controller and expects a true or false in the object named data.
$("#btnReview").click(function () {
var data = {
'id': '1',
'recordID': selectedInspectionId, 'RoleRemarks': $("#CNGInspectionReport_RoleRemarks").val()
};
$.post('/CNGInspectionReport/ChangeStatus', data, function (data) {
if (data == false) {
alert('Something went wrong');
}
else {
alert('Record reviewed successfully. Kindly review the further records, if any.');
}
});
});
and
public ActionResult ChangeStatus(int id, int recordID, string RoleRemarks, string Role = "") // Later, this should be converted to an object instead of parameters
{
try
{
using (UnitOfWork uwork = new UnitOfWork())
{
CNGInspectionReportDAL = new CNGInspectionReportDAL();
User user = (User)Session["User"];
CNGInspectionReport CNGInspectionReport = uwork.CNGInspectionReportRepository.GetByID(recordID);
CNGInspectionReport.CNGInspectionReportID = recordID;
bool statusCrossOffice = false;
if (id == 1) //Reviewed
{
if(user.Office.Trim() != CNGInspectionReport.StationName.Trim())
{
return Json(new { data = statusCrossOffice, message = "Sorry, this record belongs to another office/station and can only be reviewed by the user of the same station/office" });
}
CNGInspectionReport.RoleRemarks = RoleRemarks;
CNGInspectionReport.CheckedBy = user.UserID;
CNGInspectionReport.CheckedByName = user.UserName;
CNGInspectionReport.Status = (byte)id;
CNGInspectionReport.ReviewDate = DateTime.Now;
}
return Json(new { data = status, message = "Success" });
}
}
catch (Exception ex)
{
ViewBag.Error = ex.Message;
return Json(new { data = false, message = ex.Message });
}
}
but the problem is that it still goes to the else block when returns to the Ajax call. Why? I have clearly returned Fase in data but still it goes to the else part which is NOT FALSE.
question from:
https://stackoverflow.com/questions/65891943/why-does-the-code-always-go-to-the-not-false-part-upon-returning-the-control-to 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…