Reputation: 13
Have dropdown list, which elements are defined in controller
ViewBag.AudienceFilter= new SelectList(db.Requests, "Id", "Audience");
and this dropdown on view:
@Html.DropDownList("AudienceFilter", null, htmlAttributes: new { @class = "form-control" })
this how the result looks like http://snag.gy/dkuGH.jpg
need this to make a filter, and i need one more item in dropdown: "All", what and where do i need to edit, to add this item?
Upvotes: 0
Views: 97
Reputation: 2548
To add the item to your SelectList
just do:
List<SelectListItem> list = new SelectList(db.Requests, "Id", "Audience").ToList();
var listItem = new SelectListItem();
listItem.Text = "All";
listItem.Value = "All";
list.Add(listItem);
ViewBag.AudienceFilter = new SelectList(list);
I'll add the other half of the answer when you clarify what you want.
Upvotes: 2