Сначала добавьте метод в контроллер следующим образом
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>