Returning MVC partial view to jQuery memory leak

codeg

I'm writing an application in MVC to output a table View. One of the columns in the table contains an action link that loads up a jQuery UI dialog. When I save the data from the dialog I call a GridRefresh controller method that grabs the newly stored data and returns a partial view back through ajax to repaint the grid with the new partial view html. I use the $('#mainGrid').html(data) jQuery call to overwrite the html on the page. This call does as it should and correctly replaces the contents of the Div, but I end up with a 4mb leak every-time the RefreshGrid function is called. I've tried numerous fixes from articles online including: using .empty(), .remove(), .replaceWith(), clearing jQuery.fragments, clearing the div element using javascript(getElementById). Nothing seems to work.

Note: The data size of the response with the html view is around 1.2MB, could the size be causing my troubles? I am using MVC3 with jQuery 1.10.2 and IE9

MVC Controller

[HttpPost]
public PartialViewResult RefreshGrid(DateTime effectiveDate, String searchVal)
{
    if (Request.IsAjaxRequest())
    {
        var gridModel = new GridModel();

        LoadGridDataFromDB(effectiveDate,searchVal);
        return PartialView("Grid", gridModel);
    }

    return null;
}

Ajax/jQuery

$.ajax({
  url: "Home/RefreshGrid",
  type: "post",
  data: {
         effectiveDate: effectiveDate,
         searchVal: searchVal
  },
  dataType: "html",
  success: function(data){
    alert("success");
    $("#mainGrid").html(data);
  },
  error:function(){ alert("failure");}
});
Vasil Dininski

Have you tried accomplishing the same functionality using plain MVC - Ajax.BeginForm should do the trick. I have used it numerous times and I have never noticed any memory leaks. A simple example would be

View.cshtml

@using (Ajax.BeginForm("Action_name", "Controller_name", new AjaxOptions {
                                        InsertionMode = InsertionMode.Replace,
                                        HttpMethod = "POST"
                                        ...})
{
   Html.Partial("PartialView_name")
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MVC Ajax returning Partial view but it is not showing

From Dev

Returning a partial view with Ajax, MVC 3

From Dev

Loading JQuery in Partial View on MVC

From Dev

jquery Ui tooltip from partial view mvc

From Dev

JQuery Ajax MVC Partial View Not working

From Dev

jQuery.each on div in partial view always returning 1

From Dev

jQuery.each on div in partial view always returning 1

From Dev

Jquery/Javascript memory leak

From Dev

Memory leak deleting backbone view

From Dev

Android memory leak Custom view

From Dev

MVC Partial View and Models

From Dev

MVC Partial View not rendering

From Dev

MVC Partial View Javascript

From Dev

Returning both Partial View and a Message

From Dev

returning a partial view from a for loop

From Dev

Returning partial view in specific folder

From Dev

unable to update partial view using jquery ajax in mvc 4

From Dev

How to add or remove partial view Asp.net mvc with jquery?

From Dev

JQuery ui autocomplete in a MVC partial view only works once

From Dev

Posting partial view form from Jquery dialog using MVC

From Dev

JQuery Dialog box opens before MVC update Partial View

From Dev

Is it possible to render partial view from jquery in ASP MVC

From Dev

How to call button in Partial View from jQuery script (MVC)

From Dev

Posting partial view form from Jquery dialog using MVC

From Dev

Memory leak after returning xmlChar from function

From Dev

Will returning nil in init cause a memory leak?

From Dev

returning a char* array as string -> memory leak?

From Dev

Memory Leak: Reading and returning line from file

From Dev

Rendering a partial view with jquery