How to fail the mvc controller on purpose and do nothing

2 posts, 0 answers
  1. Gaurav
    Gaurav avatar
    14 posts
    Member since:
    Nov 2014

    Posted 23 Jun Link to this post

    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" }))
          )
    )
  2. Gaurav
    Gaurav avatar
    14 posts
    Member since:
    Nov 2014

    Posted 23 Jun in reply to Gaurav Link to this post

    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');}});

  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top