2010-06-03 36 views

回答

0

2個選項真的...要麼分裂基於服務器的形式後成多個步驟,或者使用jQuery來處理這種行爲JIT

1

首先Add方法在控制器如下

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>