2010-06-03 5 views
0

모두 드롭 다운 목록을 필터링하려고하면 모든 사용자에게 문제가 발생합니다.asp.net MVC 웹 응용 프로그램의 다른 드롭 다운 목록을 사용하여 드롭 다운 목록을 필터링하는 방법

같은보기/양식의 회사 드롭 다운 목록을 사용하여 에이전트 드롭 다운 목록을 필터링하려는 경우가 있습니다. 선택한 회사에만 속한 상담원을 표시해야하므로 그러나 나는 그렇게 할 생각이 없습니다.

아무 해결책이라도?

답변

0

이 옵션 정말 ... 하나는이 행동 JIT를 처리하기 위해 서버 기반의 여러 단계에 양식을 게시 또는 사용 jQuery를 분할

1

먼저

MvcApplication2.Models.MySampleDBEntities db = new Models.MySampleDBEntities(); 
public ActionResult SearchNames(string ddlcontent) 
{ 
var list = new List<string>(); 
var nameqry = from n in db.Images 
select n.PlayerName; 
list.AddRange(nameqry.Distinct()); 
ViewBag.ddlcontent = new SelectList(list); 
var names = from m in db.Images 
select m; 
if (string.IsNullOrEmpty(ddlcontent)) 
return View(names); 
else//Filter content basedon dropdownlist selected item 
return View(names.Where(s => s.PlayerName.Contains(ddlcontent))); 
} 
다음

바인드를 다음과 같이 컨트롤러의 메소드를 추가 보기로는 다음과 같습니다.

@model IEnumerable<MvcApplication2.Models.Image> 
@{ 
ViewBag.Title = “SearchNames”; 
} 

<h2>SearchNames</h2> 
@using (@Html.BeginForm(“SearchNames”, “Names”, FormMethod.Get)) 
{ 
@Html.DropDownList(“ddlcontent”, “All”)<input type=”submit” value=”Filter” />; 
} 
<table border=”4″ style=”border: medium dashed #FF0000″> 
<tr> 
<th> 
PlayerName 
</th> 
<th> 
Play 
</th> 
<th> 
CountryName 
</th> 
<th> 
Image 
</th> 
<th></th> 
</tr> 

@foreach (var item in Model) { 
<tr> 
<td> 
@Html.DisplayFor(modelItem => item.PlayerName) 
</td> 
<td> 
@Html.DisplayFor(modelItem => item.Play) 
</td> 
<td> 
@Html.DisplayFor(modelItem => item.CountryName) 
</td> 
<td> 
<img src=”@item.ImagePath” height=”100″ width=”100″/> 
</td> 
</tr> 
} 

</table> 
관련 문제