私はフォーラムを見回していて、ドロップダウンを使用してインデックスページをフィルタリングしようとしています。
これが私が思いついたものです。
まず第一に、私のコントローラーは次のようになります:
public ActionResult Index(string searchString)
{
var projects = from s in db.Project select s;
var themeList = db.Theme.ToList();
var projectList = db.Project.ToList();
if (Request.Form["FilterTheme"] != null && Request.Form["FilterTheme"] != "")
{
int i = int.Parse(Request.Form["FilterTheme"]);
projects = from s in db.Project
from c in s.Themes
where c.ThemeID == i
select s;
}
if (Request.Form["Styles"] != null && Request.Form["Styles"] != "")
{
int i = int.Parse(Request.Form["Styles"]);
projets = from s in db.Project
where s.ID == i
select s;
}
ViewData["Theme"] = new SelectList(themeList,"ThemeID", "Name");
ViewData["Style"] = new SelectList(projectList, "ID", "Style");
return View(projects);
}
そして、ビューは次のようになります:
@using (Html.BeginForm())
{
<table>
<thead>
<tr align="left">
<th>
Project name :
</th>
<th>
Theme(s) :
<br /><br />
@Html.DropDownList("FilterTheme", (SelectList)ViewData["Theme"], "Select a theme", new { onchange = "this.form.submit()" })
</th>
<th>
Style :
<br /><br />
@Html.DropDownList("Styles", (SelectList)ViewData["Style"], "Select a style", new { onchange = "this.form.submit()" })
</th>
<th>
Date :
</th>
</tr>
</thead>
<tbody>
...
</tbody>
</table>
}
ついに出来ました!!!
スタイルドロップダウン内の重複を削除したい場合、それはどのように機能しますか?