Error Handling

Capture error using dataSource error event

  var dataSource = new kendo.data.DataSource({
      error: function(e) {
          var xhr = e.xhr;
          var statusCode = e.status;
          var  errorThrown = e.errorThrown;

          $('#KendoGrid').data("kendoGrid").cancelChanges();
      }
  });

Capture error in complete event


  // Kendo Grid code  
   complete: function (jqXhr, textStatus) {
           if (textStatus == "success") {
              $('#inventoryItemsDetail').data('kendoGrid').dataSource.read();
              $('#inventoryItemsDetail').data('kendoGrid').refresh();
              toastr.success('Updated successfully.', 'Consumption Edit');
          } else {
          // output custom exception message 
          toastr.error(jqXhr.responseText, 'Consumption Edit');
          $('#inventoryItemsDetail').data('kendoGrid').cancelChanges();
         }
  }

  // ASP.NET MVC Controller 

  [HttpPost]
  public ContentResult Update(IEnumerable<InventoryItemDto> products)
  {
     try
     {
       var updateInventoryItemsCommand = new UpdateInventoryItemsCommand();

       foreach (var inventoryItemDto in products)
       {
         updateInventoryItemsCommand.InventoryItems.Add(inventoryItemDto);
       }

       _commandBus.Submit(updateInventoryItemsCommand);
        return new ContentResult { Content = "[]", ContentType = "application/json", ContentEncoding = Encoding.UTF8 };

     }
     catch (Exception ex)
     {

       Response.StatusCode = (int)System.Net.HttpStatusCode.ExpectationFailed;

       //Log your exception
       return new ContentResult { Content = ex.Message, ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
      }

  }

results matching ""

    No results matching ""