У меня есть представление, в котором есть таблица, отображающая значения. Я хотел бы добавить раскрывающийся список, который фильтрует результаты столбца состояния. Так, например, если я выберу «Обзор», появятся только записи с статусом «Обзор». Ниже я вижу свое мнение.C# MVC фильтрация таблицы по выпадающему меню
@model IEnumerable<DRT.Models.Master>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.RequestType.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Reviewer.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Status.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.ProjectName)
</th>
<th>
@Html.DisplayNameFor(model => model.ProjectLocation)
</th>
<th>
@Html.DisplayNameFor(model => model.Requestor)
</th>
<th>
@Html.DisplayNameFor(model => model.DateReceived)
</th>
<th>
@Html.DisplayNameFor(model => model.ReviewCompDate)
</th>
<th>
@Html.DisplayNameFor(model => model.ProjectFolerLink)
</th>
<th>
@Html.DisplayNameFor(model => model.ModellingReferralDate)
</th>
<th>
@Html.DisplayNameFor(model => model.ModellingReviewCompletionDate)
</th>
<th>
@Html.DisplayNameFor(model => model.SewerMaintenanceReferralDate)
</th>
<th>
@Html.DisplayNameFor(model => model.SewerMaintenanceReviewCompletionDate)
</th>
<th>
@Html.DisplayNameFor(model => model.FlowControlReferralDate)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RequestType.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Reviewer.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectLocation)
</td>
<td>
@Html.DisplayFor(modelItem => item.Requestor)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateReceived)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReviewCompDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectFolerLink)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectComments)
</td>
<td>
@Html.DisplayFor(modelItem => item.DischargeLocationID)
</td>
<td>
@Html.DisplayFor(modelItem => item.DischargeDistrict)
</td>
<td>
@Html.DisplayFor(modelItem => item.SystemType)
</td>
<td>
@Html.DisplayFor(modelItem => item.AffectedRequlator)
</td>
<td>
@Html.DisplayFor(modelItem => item.StartDateOfDischarge)
</td>
<td>
@Html.DisplayFor(modelItem => item.DurationOfDischarge)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequestFlowRate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ApprovedDischargeRate)
</td>
<td>
@Html.DisplayFor(modelItem => item.DischargeLocationComments)
</td>
<td>
@Html.DisplayFor(modelItem => item.ModellingReferralDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ModellingReviewCompletionDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.SewerMaintenanceReferralDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.SewerMaintenanceReviewCompletionDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.FlowControlReferralDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.MasterId }) |
@Html.ActionLink("Details", "Details", new { id=item.MasterId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.MasterId })
</td>
</tr>
}
</table>
Я не уверен, с чего начать. У меня очень мало опыта использования MVC, кроме создания стандартных представлений и контроллеров. Большинство фильтров, которые я нашел, были получены через окно поиска, которое будет фильтровать результаты. –
См. Раздел в этой ссылке «Фильтр с использованием DropDownList» http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/filter-records-in-mvc/ –