本文主要是介绍@Html.DropDownList下拉简单实用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
controller
atmcusomers是dbcontext对应的表
ViewBag.CustomerType = new MultiSelectList(db.AtmCustomers.Where(a => a.Deleted == false).OrderBy(a => a.Name).ToList(), "Id", "Name", null);
ViewBag.ATMModelType = new MultiSelectList(db.SysProjects.Where(a => a.Deleted == false).OrderBy(a => a.Name).ToList(), "Id", "Name", null);
// , null);
view
@Html.DropDownList("CustomerType", (MultiSelectList)ViewBag.CustomerType, new { @class = "chosen-select", multiple = "multiple", style = "width:370px;height:33px;" })
<th>Branch Type</th>
<td colspan="2">
<div class="col-xs-4">
@Html.DropDownList("ATMModelType", (MultiSelectList)ViewBag.ATMModelType, new { @class = "chosen-select", multiple = "multiple", style = "width:370px;height:33px;" })
</div>
</td>
设置默认值
<script>
$(function () {
//debugger
$("#CustomerType").attr("data-placeholder", "ALL");
$("#ATMModelType").attr("data-placeholder", "ALL");
})
</script>
这篇关于@Html.DropDownList下拉简单实用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!