控制器:产品和操作:保存,返回JsonResult。如果发生陷阱异常,我想用自定义错误消息向客户端(即:jQuery)发出错误信号。如何在服务器和客户端上实现?我可以在这种情况下使用函数指针错误吗?
以下是客户端代码:
$.ajax({
url: '/Products/Save',
type: 'POST',
dataType: 'json',
data: ProductJson,
contentType: 'application/json; charset=utf-8',
error: function ()
{
//Display some custom error message that was generated from the server
},
success: function (data) {
// Product was saved! Yay
}
});