I have created a project in which I have added all java script and jQuery references. I have opened a popup. this popup have multiple links. By clicking on link we are getting values directly from controller action method by hitting it using Ajax call. And display html below the link like accordion. But some time (usually when I click on link after 3 or 4 minutes.) Ajax call takes too much time to populate values from controller. When I put debugger on action method from which it should get data. It is not hitting that action quickly. Ajax call starts but hit action method about 60 sec later or more. What could be the reason behind it? Below is my code.
Method to call.
public string SavedReportHtml(string SessionID)
{
DataView dvFileInfo = dtFileInfo.DefaultView;
dvFileInfo.Sort = "CreationTime desc";
returnHtml.Append("<table id='tblSavedReport' class='table table-condensed table-striped table-bordered' style='text-align:center; valign:middle;'><tbody>");
returnHtml.Append("<tr><td style='width:10%;'><b>Select File</b></td><td style='width:20%;'><b>File Name</b></td>");
returnHtml.Append("<td style='width:40%;'><b>Description</b></td><td style='width:20%;'><b>Date Created</b></td>");
returnHtml.Append("<td style='width:10%;'><b>Delete File</b></td></tr>");
for (int rCount = 0; rCount < dvFileInfo.Count; rCount++)
{
string url_content = Url.Content("~") + "/UserIDs/" + m_userID + "/" + dvFileInfo[rCount]["Name"].ToString();
returnHtml.Append("<tr><td><input type='image' src='../../../Images/PdfImg.jpg' id='" + "" + "' class='imgrounded' width='20px' value='" + url_content + "'/></td>");
returnHtml.Append("<td>" + dvFileInfo[rCount]["Name"].ToString() + "</td>");
returnHtml.Append("<td>" + dvFileInfo[rCount]["FileDesc"].ToString() + "</td>");
returnHtml.Append("<td>" + string.Format("{0:MMM dd, yyyy}", Convert.ToDateTime(dvFileInfo[rCount]["CreationTime"].ToString())) + "</td>");
returnHtml.Append("<td><button class='btn btn-default' value='" + dvFileInfo[rCount]["Path"].ToString() + "'><i class='icon-remove-sign'></i> Delete</button></td></tr>");
}
returnHtml.Append("</tbody></table>");
return returnHtml.ToString();
}
Ajax call to call Action method.
SessionID is stored in Hidden field.
$("#btnSavedReports").click(function () {
$("#PopupTitle").html('@Model.FullName');
$('#modelSavedReports').modal('show');
return false;
});
$('#modelSavedReports').on('show.bs.modal', function () {
$("#divSavedReportDisplay").html("");
var options = { type: "POST",
url: '@Url.Action("SavedReportHtml", "WorksiteMarketing", new { area = "VitalLTC" })',
cache: false,
data: { SessionID: SessionID },
success: function (data) {
$("#divSavedReportDisplay").html(data);
$('#modelSavedReports').appendTo('body');
$("#tblSavedReport td").click(function () {
if ($(this).index() == 0) {
var fileLocation = $(this).children().attr('value');
myWindow = window.open(fileLocation, 'Wkmt', "width=800,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=no");
try {
myWindow.focus();
}
catch (e) {
myWindow.close();
myWindow = window.open(fileLocation, 'Wkmt', "width=800,height=450,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes,location=no");
}
}
else if ($(this).index() == 4) {
var $tr = $(this).closest('tr');
var myRow = $tr.index();
if (myRow != 0) {
$tr.remove();
var fileLocation = $(this).children().attr('value');
$.ajax({ data: { FileLocation: fileLocation }, cache: false, url: '@Url.Action("DeleteWkmtReport", "WorksiteMarketing")' });
}
}
else {
return false;
}
});
}
};
$.ajax(options);
});