I got a little problem with ViewBag and DropDownListFor. Code below Working fine but i need add ‘by hand’ one item with value 0. Any ideas how i can do this ?
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 for help
I use a static method for building the SelectList. Somewhere in the model put something like:
In your wiew you refer to this via