因此,我有一个AJAX
函数,该函数使用参数调用控制器中的视图。调试时,一切正常,返回正确的结果,但未在浏览器中重新加载页面。我正在使用AJAX
将过滤器应用于列表,但是现在视图已正确设置,但在浏览器中没有重新加载/刷新列表。然后,当我自己重新加载时,我得到的列表中没有过滤器。 (这很有意义)
例如:我有一个包含猫和狗的列表,并且仅对狗应用过滤器,而ajax调用完成后,我仍然在列表中保留了猫。我花了很长时间寻找答案,但没有找到一架喷气机。
在成功函数中添加location.reload();
也不起作用,因为然后使用其他参数调用了该视图,然后在AJAX
调用中设置了该参数。
所以我只想进行一个AJAX
调用,该调用以p_applicationId
作为参数调用视图,并且它们显示通过AJAX
调用的视图
AJAX
$(document).ready(function ()
{
$("#applicationDropdown").change(function () {
var releaseId = $("#applicationDropdown").val();
var filterReport = $("#filterReport");
$.ajax({
type: "POST",
url: '@Url.Action("Index", "ProductionDeployment")',
data: { p_applicationId: releaseId },
success: function (data)
{
filterReport.html('Success, The Releases have been filtered.');
},
error: function (xhr, ajaxOptions, thrownError)
{
filterReport.html('Failed to filter the Releases. ' + thrownError);
// alert('Failed to filter the Releases.', xhr, thrownError);
}
});
});
});
ProductionDeploymentController.cs
public class ProductionDeploymentController : BaseController
{
// Variable Initialisation
DBhandler dbhandler = new DBhandler();
string cnnStr = ConfigurationManager.ConnectionStrings["conChdbd1"].ConnectionString;
string sqlStr;
/// <summary>
/// GET: ProductionDeployment
/// </summary>
/// <returns> Function Return View </returns>
public ActionResult Index(String p_applicationId)
{
if (p_applicationId == null)
{
p_applicationId = "CTTS";
}
PrepareViewBagJustApplication();
List<ProductionPending> pendingDeployments = GetPendingProductionDeployments(p_applicationId);
ProductionDeployments pd = new ProductionDeployments();
pd.Pending = pendingDeployments;
return View(pd);
}
/// <summary>
/// Function contains a SQL which links to a Package, which is sent to the DBHandler and returns a DataTable,
/// The DataTable then is then converted into a List<> in the ConvertTo...() function and passed back to the View.
/// </summary>
/// <returns> List of Pending Productions: List<ProductionPending> </returns>
private List<ProductionPending> GetPendingProductionDeployments(String p_applicationId)
{
List<ProductionPending> list = null;
sqlStr = "ADM_PORTAL_REP.p_PendingProdDeployments";
DataTable dt = dbhandler.ExecuteQuery(sqlStr, "2016-04", p_applicationId);
if (dt.Rows.Count > 0)
{
list = ConvertToProductionPending(dt).ToList();
}
else
{
list = new List<ProductionPending>();
list.Clear();
}
return list;
}
/// <summary>
/// Function to convert the DataTable sent in into an IEnumerable<ProductionPending>
/// </summary>
/// <param name="dt"></param>
/// <returns> IEnumerable of Pending Productions: IEnumerable<ProductionPending> </returns>
private IEnumerable<ProductionPending> ConvertToProductionPending(DataTable dt)
{
return dt.AsEnumerable().Select(row =>
{
return new ProductionPending
{
Id = Convert.ToInt32(row["ID"]),
releaseId = row["releaseId"].ToString(),
RFCNumber = Convert.ToInt32(row["RFCNumber"]),
developerInitials = row["developerInitials"].ToString(),
fileName = row["fileName"].ToString(),
fileVersion = row["fileVersion"].ToString(),
RFDNumber = Convert.ToInt32(row["RFDNumber"]),
desiredDeploymentDate = Convert.ToDateTime(row["desiredDeploymentDate"]),
deploymentDate = Convert.ToDateTime(row["deploymentDate"]),
notes = row["notes"].ToString(),
detailNotes = row["detailNotes"].ToString(),
approvedInd = row["approvedInd"].ToString(),
dateRequested = Convert.ToDateTime(row["dateRequested"]),
applicationId = row["application"].ToString(),
};
});
}
}