ASP.NET MVC下拉一个默认的空选项 [英] ASP.NET MVC dropdown with a default empty option
本文介绍了ASP.NET MVC下拉一个默认的空选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法,包括一个默认为空选项(或文本)如果对于一个DropDownList没有选定值?
Is there a way to include a default empty option (or with text) if there is no selected value for a dropdownlist?
推荐答案
下面将prePEND的String.Empty到选择列表(或IEnumerable的)在计算机[菜单]项中指定。选择将有标识和名称 MENUID
。
The below will prepend string.Empty to the SelectList (or IEnumerable) specified in the ViewData["Menu"] item. The select will have id and name MenuID
.
<%= Html.DropDownList( "MenuID",
(IEnumerable<SelectListItem>)ViewData["Menu"],
string.Empty ) %>
文档: DropDownList的方法
这篇关于ASP.NET MVC下拉一个默认的空选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文