我的模型看起來像這樣。它通過存儲過程在某個時間填充項目。ASP.NET MVC DropDownListFor
public class myModel
{
public List<SelectListItem> myList { get; set; }
public List<myModel> modelList { get; set; }
}
這是我的控制器。
[HttpGet]
public ActionResult getMyListItems()
{
var viewModel = new myModel();
viewModel.myList = viewModel.getMyList();
viewModel.modelList = viewModel.getMyModelList();
return View(viewModel);
}
這是我目前爲止的觀點。我正在構建一個下拉列表,以便用戶可以過濾modelList的內容。有點像SQL查詢中的WHERE子句。一旦用戶選擇該項目並點擊提交按鈕,它將應用過濾器?或者在沒有按鈕點擊事件的情況下在下拉菜單中選擇了一個項目後會發生這種情況?
@model SWAM2.Models.EmployeeOfcSpecKnow
@using CommonCode.HtmlHelpers;
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="editor-label">
Filter by Column1
</div>
<div class="editor-field">
@Html.DropDownListFor(model => Model.Column1, Model.myList, new { style = "width:400px" })
@Html.ValidationMessageFor(model => model.Column1)
</div>
<div class="toppad10">
<input type="submit" value="Apply Filter" />
</div>
<table class="grayTable rowStriping">
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</tr>
</thead>
<tbody>
@foreach (var item in @Model.modelList)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Column1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Column2)
</td>
<td>
@Html.DisplayFor(modelItem => item.Column3)
</td>
</tr>
}
</tbody>
</table>
}