error, , , ( , , , IIS , ). . http://api.jquery.com/jQuery.ajax/.
, , - , , JsonResult, error ErrorCode, JS .
, :
public ActionResult Save()
{
ActionResult result;
try
{
}
catch(Exception)
{
result = new JsonResult()
{
Data = new { Error = true, ErrorMessage = "Product could not be saved." }
};
}
return result;
}
JavaScript, :
$.ajax({
url: '/Products/Save',
'POST',
'json',
ProductJson,
'application/json; charset=utf-8',
error: function ()
{
},
success: function (data) {
if (data.Error) {
window.alert(data.ErrorMessage);
}
else {
}
}
});
, .