I needs to show the Json returned message.
In the controller, an exception is thrown and caught in a catch block. I am returning the fault error message.
In Ajax, the success part always executes. But if it is an error from my webservice, I don't want to execute the normal; instead I want to show an error message.
How I can achieve this?
My code below:
[HttpPost]
public JsonResult DeleteClientRecord()
{
    bool result = true;
    try
    {
        result = ClientCRUDCollection.DeleteClient(deleteClientId);
    }
    catch (Exception ex)
    {
        return Json(ex.Message, JsonRequestBehavior.AllowGet);
    }
    return Json(new { result }, JsonRequestBehavior.AllowGet);
}
$("#YesDelete").click(function () {
    $.ajax({
        type: "POST",
        async: false,
        url: "/Client/DeleteClientRecord",
        dataType: "json",
        error: function (request) {
            alert(request.responseText);
            event.preventDefault();
        },
        success: function (result) {
            // if error from webservice I want to differentiate here somehow
            $("#Update_" + id).parents("tr").remove();
            $('#myClientDeleteContainer').dialog('close');
            return false;
        }
    });
});
Please can anyone help me on this.
[HttpPost]
public JsonResult DeleteClientRecord()
{
         bool result = true;
         try
         {
            result = ClientCRUDCollection.DeleteClient(deleteClientId);
         }
         catch (Exception ex)
         {
            return Json(new { Success="False", responseText=ex.Message});
         }
    return Json(new { result }, JsonRequestBehavior.AllowGet);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With