0
每個人,當我嘗試過濾下拉列表時遇到問題。如何使用asp.net MVC web應用程序中的其他下拉列表來過濾下拉列表
這種情況是我希望通過在同一視圖/表單中使用公司下拉列表來過濾代理下拉列表。因爲我需要顯示只屬於選定公司的代理。但我不知道這樣做。
任何解決方案,請?
每個人,當我嘗試過濾下拉列表時遇到問題。如何使用asp.net MVC web應用程序中的其他下拉列表來過濾下拉列表
這種情況是我希望通過在同一視圖/表單中使用公司下拉列表來過濾代理下拉列表。因爲我需要顯示只屬於選定公司的代理。但我不知道這樣做。
任何解決方案,請?
2個選項真的...要麼分裂基於服務器的形式後成多個步驟,或者使用jQuery來處理這種行爲JIT
首先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>