1
不確定bext方法如何向客戶端顯示db異常(ajax調用)?我應該在控制器波紋管中放置一個try/catch嗎?目前,我得到了我的ajax調用的通用異常?從mvc控制器顯示db異常到我的ajax調用?
控制器:
// GET: Agency Grants
public JsonResult GetAgencyGrants(int agencyID)
{
AuditDAL ad = new AuditDAL();
var grants = ad.GetAgencyGrants(agencyID); //exception here
return this.Json(grants.ToList());
}
Ajax調用:
function GetAuditTypes(container) {
$.ajax({
url: '/AMS/Audit/GetAuditTypes',
type: 'post',
success: function (result) {
$.each(result, function (i, item) {
container.append($('<option/>').text(result[i].Audit_Type_Desc).attr('value', result[i].Audit_Type_ID));
});
},
error: function (xhr, err) {
alert("GetAuditTypes not returned: " + formatErrorMessage(xhr, err));
}
});
}
格式化功能:
// formats errors returned
function formatErrorMessage(jqXHR, exception) {
if (jqXHR.status === 0) {
return ('Not connected.\nPlease verify your network connection.');
} else if (jqXHR.status == 404) {
return ('The requested page not found. [404]');
} else if (jqXHR.status == 500) {
return ('Internal Server Error [500].');
} else if (exception === 'parsererror') {
return ('Requested JSON parse failed.');
} else if (exception === 'timeout') {
return ('Time out error.');
} else if (exception === 'abort') {
return ('Ajax request aborted.');
} else {
return ('Uncaught Error.\n' + jqXHR.responseText);
}
}
我不斷收到,而不是存儲過程內部服務器錯誤缺少(真正的例外)。