Катерина
Катерина

Reputation: 404

ASP MVC Refresh partial view grid

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. enter image description here

Appears that it's going to the right controller

Upvotes: 1

Views: 1257

Answers (1)

kari kalan
kari kalan

Reputation: 505

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

Upvotes: 2

Related Questions