2
현재 두 개의 테이블 (팀 및 직원)이 있습니다 팀의 dropdownList를 완벽하게 채우고 있습니다. 다음으로 Employees 팀의 selectedId에 따라 두 번째 드롭 다운 목록을 채우려고합니다.ASP.NET MVC의 종속 드롭 다운 목록
컨트롤러 :
// GET: CalView
public ActionResult Index(string ses, string DH)
{ //Team Lead Members
var eID = Convert.ToInt32(Session["currentEmployeeID"]);
var EmpID = Session["currentEmpID"];
Employee obj = (from o in db.Employees
where o.EnrollNumber == EmpID
select o).FirstOrDefault();
Department dept = (from dep in db.Departments
where dep.LeadBy == obj.EmployeeId
select dep).FirstOrDefault();
//this works fine
ViewBag.showTeams = new SelectList(db.Teams.Where(tm => (tm.DeptID == dept.DepartmentId) && (dept.LeadBy == eID)), "TeamID","Name");
//this obviously does not
ViewBag.showMembers = new SelectList(db.Employees.Where(empt => (empT.TeamID == selectedIdFromPreviousDropDownList), "EmployeeID", "Employee"));
return View();
}
보기 :
if ((Session["UT"] == "DD") && (@ViewBag.DeptLead != null))
{
//this works
@Html.DropDownList("showTeams", null, "-Select Team-", htmlAttributes: new { @class = "form-control" })
//this does not work
@Html.DropDownList("showMembers", null, "-Select Team-", htmlAttributes: new { @class = "form-control" })
}
가 좀 AJAX 호출이 필요하십니까? 또는 아마 POST 메서드? MVC를 처음 접했습니다.
예, 최선의 방법은 ** Ajax ** 호출, 당신은 JQuery를 사용하고 있습니까? –
가능한 [MVC 3 C#] 목록의 계단식 복제본 (https://stackoverflow.com/questions/10016560/cascading-dropdown-lists-mvc-3-c-sharp) –
[this DotNetFiddle]의 코드 연구를 제안하십시오. (https://dotnetfiddle.net/1bPZym)을 사용하여 계단식 드롭 다운 목록을 구현하는 방법 이해 –