User1520731567 posted
Hi xandeq,
I am using ASP.NET MVC, and I need to list
Events with a format like:
date - title
Do you mean you want to show date and title in dropdownlist?
If so,you just code like:
ViewBag.events_id = new SelectList(db.events.ToList(), "date", "title");
You could see the format of SelectList:
public SelectList(IEnumerable items, string dataValueField, string dataTextField);
Just put ValueField name and TextField
name on it.
How to render in view:
@Html.DropDownListFor(model => model.XXX, (IEnumerable<SelectListItem>)ViewBag.events_id , "---Select---", new { @class = "form-control" })
If I mistake your mean,please post more details.
Best Regards.
Yuki Tao