Hi!
I have a grid where I'm returning a BadRequest with a message if there is some error or enter a validation. In my view, I read in the failure function the message of the bad request and display it.
This works perfectly when Add or Delete any data. But when updating a data, this not works... is any way to make it work?
This is my method from controller:
public ActionResult Update(OrderModel value)
{
try
{
var oOrder = db.Order.Find(value.OrderID);
if (oOrder != null)
{
if (oOrder.Pet.Ingredient.Count == 0) return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Falta asignar los ingredientes de la comida");
if (value.ProductionDate.Date >= value.BaseRecurrencyDate.Date || value.ProductionDate.Date >= value.DeliveryDate.Date) return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "La fecha de producción no puede ser mayor a la fecha base de recurrencia/fecha de entrega");
oOrder.Price = value.Price;
oOrder.Paid = value.Paid;
oOrder.ProductionDate = value.ProductionDate;
oOrder.DeliveryPrice = value.DeliveryPrice;
oOrder.DeliveryAddress = value.DeliveryAddress;
oOrder.DeliveryDate = value.DeliveryDate;
oOrder.BaseRecurrencyDate = value.BaseRecurrencyDate;
oOrder.EditedByDate = Utility.ConvertToLocal(DateTime.Now);
oOrder.EditedByUser = User.Identity.Name;
db.SaveChanges();
return Json(value);
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message);
}
}
This is the failure method from the view:
function failure(args) {
ej.popups.hideSpinner(document.getElementById('OrderForm'))
if (args.error[0]) {
alert(args.error[0].error.responseText.split("HTTP Error 400.0 - ")[1].split('</h3>')[0]);
} else {
alert(args.error);
}
}
Thanks, regards!