【发布时间】:2017-07-04 11:46:34
【问题描述】:
我有 2 个下拉列表(即)mutualExcParam。它有 3 个选项。根据选择的此选项,需要填充另一个下拉列表(即)agencyRetrieve。 这是通过 JSON 请求完成的,并且可以很好地处理较少的记录。如果记录更多计数> 500,则需要加载时间。当我循环通过它时,有没有其他方法可以做同样的事情。
$(document).ready(function () {
$('.mutualExcParam').change(function () { // calling by class name on 1st dropdown
var agencyRetrieveId = $(this).attr('id') + '_'; // 2nd dropdown id
$.ajax({
type: "POST",
contentType: 'application/json',
url: "../Report/FillAgencyValue",
data: JSON.stringify({ agencyId: agencyId}),
success: function (data) {
$('#' + agencyRetrieveId).html('');
var optionhtml1 = '<option value="All">Select All</option>';
$('#' + agencyRetrieveId).append(optionhtml1);
$(data).each(function () {
$('#' + agencyRetrieveId).append($("<option></option>").val(this.Value).html(this.Text));
});
$(".selectpicker").selectpicker('refresh');
}
});
});
});
[HttpPost]
public ActionResult FillAgencyValue(int agencyId, string fromDate, string toDate, int salesArea, string[] salesGroup)
{
AppCode.CommonCommands commonCommands = new AppCode.CommonCommands();
PopulateControlData populateControlData = new PopulateControlData();
// Get all Sales Area
DataTable dtsalesArea = commonCommands.GetAgencyDropdownData(agencyId, fromDate, toDate, salesArea, salesGroup);
populateControlData.agencyValues = new List<SelectListItem>();
if (dtsalesArea.Rows.Count > 0)
{
populateControlData.agencyValues = (from DataRow row in dtsalesArea.Rows
select new SelectListItem
{
Text = row["ParameterLabel"].ToString(),
Value = row["ParameterValue"].ToString()
}).ToList();
}
return Json(populateControlData.agencyValues, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
您可以考虑从您的
FillAgencyValue返回 HTML。 -
是的。还添加了控制器代码和平。
标签: jquery json asp.net-mvc asp.net-mvc-4 asp.net-mvc-5