My model looks something like this. It gets populated with items at some point by a stored procedure.
public class myModel
{
public List<SelectListItem> myList { get; set; }
public List<myModel> modelList { get; set; }
}
Here is my Controller.
[HttpGet]
public ActionResult getMyListItems()
{
var viewModel = new myModel();
viewModel.myList = viewModel.getMyList();
viewModel.modelList = viewModel.getMyModelList();
return View(viewModel);
}
Here is my view so far. I'm building a dropdownlist so the user can filter the contents of modelList. Kind of like a WHERE clause in an SQL query. Once the user selects the item and clicks the submit button, it applies the filter? Or would this happen after an item is actually selected in the dropdown without the need of a button click event?
@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>
}