Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created February 1, 2016 23:48
Show Gist options
  • Save vendettamit/fbb5a6bb88455744bc22 to your computer and use it in GitHub Desktop.
Save vendettamit/fbb5a6bb88455744bc22 to your computer and use it in GitHub Desktop.
MyDbContext db = new MyDbContext();
List<SelectListItem> selectedItems = new List<SelectListItem>();
if (type == null) return selectedItems;
if (type == typeof(TestDemo))
selectedItems = db.TestDemo.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList();
if (type == typeof(TestDemo1))
selectedItems = db.TestDemo1.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList();
if (type == typeof(TestDemo2))
selectedItems = db.TestDemo2.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList();
if (type == typeof(TestDemo3))
selectedItems = db.TestDemo3.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment