touinta
touinta

Reputation: 1031

Update partial view wtih webgrid after delete a row ajax MVC 5

I need to update a webgrid which is being call in a partial view.

I load my partial view through Ajax.ActionLink

 @Ajax.ActionLink(" ", "ShowAssistants", "Assistants", new { assistusername = item.AssistantUserName }, new AjaxOptions() { UpdateTargetId = "add_research" }, new { @class = "glyphicon glyphicon-link" })

In this partial view I have a webgrid in which one column has delete action method

 @Html.Raw("<a data-modal='' href='/Assistants/DeleteAssistant/" + item.ID + "' id='" + item.ID + "' title='Delete'> <span class='glyphicon glyphicon-trash'> </span> </a>")

I call a modal which just ask the user if wants to delete the row. After he press the yes button the record has been deleted but the partial view and webgrid is not updated.

ajax code

function bindForm(dialog) {
$('form', dialog).submit(function () {
    $('#progress').show();
    $.ajax({
        url: this.action,
        type: this.method,
        data: $(this).serialize(),
        cache: false,
        success: function (result) {
            if (result.success) {
                $('#myModal').modal('hide');
                $('#progress').hide();
               //location.reload();

                $("#add_research").load('@Url.Action("ShowAssistants", "Assistants")');

            } else {
                $('#progress').hide();
                $('#myModalContent').html(result);
                bindForm();
            }
        }
    });
    return false;
});
  }

If I remove the $("#add_research").load('@Url.Action("ShowAssistants", "Assistants")');

and leave the location.reload();

it refresh the page but the partial view is being disappeared which is normal. And the user has to click the Ajax.ActionLink so to see the records again. Any idea on how to kept the partial view in the page and to upgrade the webgrid? Thank you!

Upvotes: 0

Views: 654

Answers (1)

kkakkurt
kkakkurt

Reputation: 2800

I use ajax load function like this and it loads partial view successfully:

$("#add_research").load('/Assistants/ShowAssistants');

Upvotes: 1

Related Questions