Remove duplication's from my DropDownList
Posted
by
user2976270
on Stack Overflow
See other posts from Stack Overflow
or by user2976270
Published on 2013-11-10T14:57:36Z
Indexed on
2013/11/10
15:54 UTC
Read the original article
Hit count: 148
c#
|asp.net-mvc
In my controller i am returning list of my object with specific property:
public ActionResult Index()
{
List<MyObject> list = db.MyObjects.Where(x => x.family == "Web").ToList();
ViewBag.Files = new SelectList(list, "Id", "protocol");
return View();
}
This is my object:
public class MyObject
{
public int id { get; set; }
public string fileName { get; set; }
public string browser { get; set; }
public string protocol { get; set; }
public string family { get; set; }
}
Index.cshtml:
@Html.DropDownList("File", new SelectList(ViewBag.Files, "Id", "protocol_site"), "Select webmail site", new { style = "vertical-align:middle;" })
And i try to made 2 changes with no succeed:
Remove all the duplication protocol from my
DropDownList
for exapmle if i have 10 objects : 9 is doc protocol and 1 pdf i wand to see in myDropDownList
only 2 items: DOC and PDF and not all the 10 items.Sort this
DropDownList
in alphabet order
© Stack Overflow or respective owner