我对 ViewBag 和 DropDownListFor 有点问题。下面的代码工作正常,但我需要“手动”添加一个值为 0 的项目。有什么想法可以做到这一点吗?
public ActionResult Create()
{
ViewBag.ParagrafyRodzic = paragrafRepository.All;
return View();
}
@Html.DropDownListFor(model => model.ParagrafID, ((IEnumerable<Projekty03.Models.Paragraf>)ViewBag.ParagrafyRodzic)
.Select(option => new SelectListItem
{
Text = option.ParagrafNazwa.ToString(),
Value = option.ParagrafID.ToString(),
Selected = (Model != null) && (option.ParagrafID == Model.ParagrafParent)
}),Translate.ChooseList)
:) Tx 寻求帮助