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");}
});
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.
Comments