ASP MVC Refresh partial view grid

23
May 19, 2017, at 6:59 PM

I am trying to refresh a partial view grid after changing a record. I have a button where the user can click on, than it will change a row in the grid. This works OK, however. I have to manually refresh the page to see the modification. Now I thought I could make a new JavaScript Ajax function to do this. So after the user push the button it will load the function RefreshGrid

JavaScript Function:

function RefreshGrid() {
    var numberPlate = $("#NumberPlate").val();
    if (numberPlate) {
        $.ajax({
            type: 'get',
            url: appPath + '/Service/Grid',
            data: { numberPlate: numberPlate },
            success: function (response) {
                $("#Grid").html(response);
            },
            error: function (response) {
                $("#dialog .modal-body").html(msgErrorDuringRequest);
                $("#dialog #dialog-title").html(errorTitle);
                $("#dialog").modal("show");
            }
        });
    }
}

Now the controller

public ActionResult Grid(string numberPlate)
        {
            IList<ServiceOrder> services = ServiceRepository.Services(numberPlate);
            return PartialView("_Grid", services);
        }

For some reason it is returning me the error function

error: function (response) {
                $("#dialog .modal-body").html(msgErrorDuringRequest);
                $("#dialog #dialog-title").html(errorTitle);
                $("#dialog").modal("show");
            }

But I have no idea where it goes wrong. Cant really imagine it is in the controller as I have a familiar function elsewhere which works flawless but perhaps I am missing something.

Answer 1

try code: Remove The All your jquery code ,just used below the code your RefreshGrid Function

var numberPlate = $("#NumberPlate").val();
 var url= '/Service/Grid?numberPlate='numberPlate;
 $("#Grid").load(url);
READ ALSO
jQuery AJAX function call

jQuery AJAX function call

I have a problem with jQuery calling an AJAX function, basically everytime a user changes a select box, I want it to call the getSubCategories function, but for some reason, nothing is happeningAny ideas?

28
How to get current state data in jquery datatable after searching sorting etc?

How to get current state data in jquery datatable after searching sorting etc?

Let I have five rows in jquery datatableAfter searching no of rows becomes say 3

47
Attach click event dynamically as below on document ready [on hold]

Attach click event dynamically as below on document ready [on hold]

The web page has 30 buttons and I loop 30 timesBut sometimes button 1 and 2 not working

26