mvc 5从表中选择列表,DropDownList的值为空白 [英] mvc 5 SelectList from table with blank value for DropDownList
本文介绍了mvc 5从表中选择列表,DropDownList的值为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码创建下拉列表
I am using below code to create a drop down
控制器
ViewBag.Id= new SelectList(db.TableName.OrderBy(x => x.Name),"Id","Name")
查看
@Html.DropDownList("Id", null, htmlAttributes: new { @class = "form-control" })
我的问题是我如何修改SelectList
以添加空白项目,以便为DropDownList
自动添加空白项目.
My question is how can I Modify SelectList
to add a blank item so that there is a blank item automatically added for DropDownList
.
谢谢.
推荐答案
查看全文