<script type="text/javascript"> function getTeams(deptCode) { $.ajax({ url: "@Url.Action("GetTeams","User")",data: { departmentCode: deptCode },dataType: "json",type: "POST",error: function () { alert("An error occurred."); },success: function (data) { var items = ""; $.each(data,function (i,item) { items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>"; }); $("#@Html.IdFor(m => m.TeamId)").html(items); } }); } $(document).ready(function () { $("#@Html.IdFor(m => m.DepartmentCode)").change(function () { var deptCode = $("#@Html.IdFor(m => m.DepartmentCode)").val(); getTeams(deptCode); }); }); </script>
根据部门ID(deptCode)获取该部门下的组(Team)。
Controller:
User的GetTeams(string departmentCode)返回一个集合,通过
$.each(data,item)进行循环添加。 原文链接:https://www.f2er.com/ajax/165833.html