我有一个onchange事件,当选择一个新的下拉列表项时,它将向控制器发出ajax请求。控制器返回一个模型,其中包含填充第二个下拉列表的新数据......这一切都发生在jQuery PopUp中,因此我的目标是使用新内容重新填充div,但Ajax中的成功函数永远不会被触发..这个逻辑应该用一个视图来替换pop up div,该视图具有基于角色下拉列表选择的新员工下拉列表..调试器中的这个后面显示模型已正确填充,我没有收到任何形式的错误,但下拉列表项目保持不变。
剃刀
<td>@Html.DropDownList("Role", (IEnumerable<SelectListItem>)ViewBag.RoleDDL, new { @class = "SimDDL", onchange = "RoleDDLChange(this)" })</td>
<td>@Html.DropDownList("EmpDDL", (IEnumerable<SelectListItem>)Model.EmpDDL, new { @class = "SimDDL" })</td>
的jQuery
function RoleDDLChange(id) {
var SelectedRole = $('#Role').find(":selected").val();
var url = '/Incentive/ImpersonationPopUp';
$.ajax
({
data: {
'DDLSelection': SelectedRole
},
type: "get",
dataType: 'json',
url: url,
//crossDomain: true,
success: function (data) {
$("#ImpDiaglog").load(data);
}
});
}
控制器
public ActionResult ImpersonationPopUp(string DDLSelection = "")
{
using (AppDataEntities IP = new AppDataEntities())
{
var Roles = IP.IncentivePayGroups.ToList()
.Select(r => new
{
r.role,
r.PayGroupID
});
if (String.IsNullOrEmpty(DDLSelection))
{
var Emps = IP.Employees.ToList()
.Where(E => E.IncentivePayGroup == "2" && E.UltiproActiveInactive != "Terminated" && E.UltiproActiveInactive != "Inactive")
.Select(e => new
{
e.UltiproEmployeeNo,
Name = e.FirstName + " " + e.LastName
}).OrderBy(e => e.Name);
SelectList EmpDDL = new SelectList(Emps, "UltiproEmployeeNo", "Name");
ImpersonationPopUp DDL = new ImpersonationPopUp(EmpDDL);
ViewBag.RoleDDL = new SelectList(Roles, "PayGroupID", "Role");
return PartialView(DDL);
}
else
{
var Emps = IP.Employees.ToList()
.Where(E => E.IncentivePayGroup == DDLSelection && E.UltiproActiveInactive != "Terminated" && E.UltiproActiveInactive != "Inactive")
.Select(e => new
{
e.UltiproEmployeeNo,
Name = e.FirstName + " " + e.LastName
}).OrderBy(e => e.Name);
SelectList EmpDDL = new SelectList(Emps, "UltiproEmployeeNo", "Name");
ImpersonationPopUp DDL = new ImpersonationPopUp(EmpDDL);
ViewBag.RoleDDL = new SelectList(Roles, "PayGroupID", "Role");
return PartialView(DDL);
}
}
return PartialView("~/Incentive/ImpersonationPopUp");
}
模型
public class ImpersonationPopUp
{
public SelectList EmpDDL {get; set;}
public ImpersonationPopUp(SelectList EmpDDL)
{
this.EmpDDL = EmpDDL;
}
}