本文介绍了@ Html.DropDownListFor如何添加选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Html.DropDownListFor(model => model.ZipFile, new SelectList(ViewBag.ZipFiles))

上面的代码为我创建了一个选择列表.但是我想将选择设为可选.不幸的是,没有空选项,我想添加一个.我该怎么做?

The above code creates me a select list just fine. But I want to make the selection optional. Unfortunately there is no empty option and I'd like to add one in. How would I do this?

推荐答案

通过使用适当的DropDownListFor重载:

@Html.DropDownListFor(
    model => model.ZipFile, 
    new SelectList(ViewBag.ZipFiles),
    "-- please select a zip file --"
)

这篇关于@ Html.DropDownListFor如何添加选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 03:37