This is a migrated thread and some comments may be shown as answers.

How to fail the mvc controller on purpose and do nothing

1 Answer 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gaurav
Top achievements
Rank 1
Gaurav asked on 23 Jun 2016, 06:40 PM
Controller Method:

        public ActionResult GetCustomerComments([DataSourceRequest] DataSourceRequest request, string invoices)
        {
            if (invoices != "fail")
            {

            List<JNI.Enterprise.Contracts.CustomerComments> customer = InvoiceService.GetCustomerComments(invoices);

            return Json(customer.ToDataSourceResult(request));
            }
            else
            {
                //do nothing
            }
        }

I am trying to upgrade the grid using ajax
        $.ajax({
            url: webManager.resolveUrl("~/maint/GetCustomerComments"),
            method: "POST",
            data: { invoices: invoicesList },
            success: function () {
                var grid = $('#CustomerCommentsGrid').data('kendoGrid');
                grid.dataSource.read();
                grid.refresh();
            },
            error: function () {
                alert('an error occurred');
            }

        });

But the problem is Grid is called again and I want to stop that.

     @(Html.Kendo().Grid<CustomerComments>()
      .Name("CustomerCommentsGrid")
      .Columns(columns =>
      {
          columns.Bound(i => i.INVOICE).Title("Invoice").Width(15);
          columns.Bound(i => i.Comment).Title("Comment").Width(40);

      }).Pageable(pageable => pageable
          .Refresh(true)
      )
      .Scrollable()
      .Sortable()
      .Filterable()
      .DataSource(dataSource => dataSource
          .Ajax().UseJniErrorHandler()
          .PageSize(10)
              .Read(read => read.Action("GetCustomerComments", "Maint", new { invoices = "fail" }))
      )
)

1 Answer, 1 is accepted

Sort by
0
Gaurav
Top achievements
Rank 1
answered on 23 Jun 2016, 09:08 PM

I am not sure if there is a solution to my original question but I was able to solve my problem by updating with following AJAX

$.ajax({ url: webManager.resolveUrl("~/maint/GetCustomerComments"), method: "POST", data: { invoices: invoicesList }, success: function (result) {var grid = $("#CustomerCommentsGrid").data("kendoGrid");var dataSource = new kendo.data.DataSource({ data: result.Data}); grid.setDataSource(dataSource); grid.dataSource.read();}, error: function () { alert('an error occurred');}});

Tags
Grid
Asked by
Gaurav
Top achievements
Rank 1
Answers by
Gaurav
Top achievements
Rank 1
Share this question
or