I am encountering an issue with a SQL store procedure failure and trying to capture the exception being thrown. Although I am receiving the response in ajax using request.responseText, I am only interested in extracting the title from this responseText.
The Controller code snippet is shown below:
public ActionResult ReOrderSegment(string DocumentIDs, long DossierIDForReOrder)
{
try
{
var TrimmedString = DocumentIDs.TrimEnd('#');
var DocumentIDsWithInteger = Convert.ToInt64(DocumentIDs.Split('#').FirstOrDefault());
long SelectedCompany = db.Documents.FirstOrDefault(x => x.ID == DocumentIDsWithInteger).CompanyID;
var Message = db.PerformAutomatedSorting(SelectedCompany, DossierIDForReOrder, TrimmedString);
return Json(Message, JsonRequestBehavior.AllowGet);
}
catch (SqlException ex)
{
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
return Json(new { errorMessage = ex.Message }, JsonRequestBehavior.AllowGet);
}
return Json(0);
}
and JS:
$.ajax({
type: 'POST',
url: rootUrl("Dossier/ReOrderSegment"),
dataType: "json",
data: { DocumentIDs: DocumentIDs, DossierIDForReOrder: DossierIDForReOrder },
traditional: true,
success: function (rest)
{
alert(rest);
},
error: function (request, status, error)
{
//var all = JSON.parse(request.responseText);
alert(request.responseText);
}
});
});
Attached are some images for reference.
In the alert message, I specifically want to display only "Please select only Air Product that are UnInvoiced".