<div style="margin-left:27px; margin-bottom:20px;">
<h2>Email Scheduler</h2>
<div id="dvtblCustomer" class="table-responsive">
<table class="table-bordered col-offset-12">
<thead>
<tr class="label-primary">
<th style="padding:5px 15px;">
Customer Designation
@Html.DropDownList("CustomerDesignation", new SelectList(Model., "Value", "Text"), new { id = "CustomerDesignationDDL", name = "CustomerDesignationDDL" })
</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tr style="text-align:center">
<td>
@item.CustomerDesignation
</td>
</tr>
}
</table>
</div>
</div>
这是我的webgrid。我想在表格标题中添加dropdownlist以进行表过滤
答案 0 :(得分:1)
类System.Web.Mvc.SelectListItem
是用于此目的的汇编类。
鉴于您的CustomerDesignation
模型是一个指定列表,然后从中构建一个List<SelectListItem>
,其中designations
是您的数据库/文件驱动的客户指定列表:
List<SelectListItem> designationList = designations.Select(d => new SelectListItem {
Text = d.CustomerDesignationDDL,
Value = d.CustomerDesignationDDL
}).ToList();
将SelectItemList
namesList绑定到视图模型
Model.Designations = designationList;
在视图中,可以填充相同的下拉列表:
@Html.DropDownListFor(model => model.Designations, Model.Designations)