c# - 使用 AJAX 调用带参数的视图
问题描述
所以我有一个AJAX
函数,它用参数调用控制器中的视图。当我调试一切正常时,我也得到了正确的结果,但页面没有在浏览器中重新加载。我正在使用将AJAX
过滤器应用于列表,但现在视图设置正确,但浏览器中没有重新加载/刷新列表。然后当我自己重新加载时,我得到的列表没有过滤器。(这是有道理的)
例如:我有一个包含猫和狗的列表,并且只为狗应用过滤器,在 ajax 调用完成后,我的列表中仍然有猫。我搜索了很长时间来寻找答案,但没有找到一架喷气式飞机。
在成功函数中添加 alocation.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);
}
});
});
});
生产部署控制器.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(),
};
});
}
}
解决方案
推荐阅读
- java - 用数据存储复杂的结构以备将来使用
- python - Pycharm Selenium Geckodriver 路径问题
- angular - 子元素初始化后,父组件对子 DOM 的操作导致 ExpressionChangedAfterItHasBeenCheckedError
- excel - 在 VBA 中禁用屏幕更新也会删除 DisplayBar 中的背景
- json - 从自定义 AMI 创建 ec2 实例时提供不同的卷标签
- botframework - 我如何在 C# 中为 Microsoft Bot 框架 V4 编写一个简单的单元测试用例,因为它现在使用 .netcore
- javascript - 当用户单击“在新选项卡中打开”时,如何重定向 iframe 内的链接?
- coq - 类型:输入 Coq
- google-compute-engine - 谷歌云 TCP LB 让 RTMP 和 HTTP(S) 工作
- node.js - node.js 命令行应用程序未运行