public void PopulateCategoriesDropDownList(Lucaci_Ioana_ProiectFinalContext _context, object selectedCategories = null) { var categoriesQuery = _context.Category .OrderBy(c => c.Name) .Select(c => new { Text = c.Name, Value = c.ID }); CategoryNames = new SelectList(categoriesQuery.AsNoTracking(), "Value", "Text", selectedCategories); }
public void PopulateAuthorsDropDownList(Lucaci_Ioana_ProiectFinalContext _context, object selectedAuthor = null) { var authorsQuery = _context.Author .OrderBy(a => a.LastName) .Select(a => new { Text = a.FirstName + " '" + a.Nickname + "' " + a.LastName, Value = a.ID }); AuthorNames = new SelectList(authorsQuery.AsNoTracking(), "Value", "Text", selectedAuthor); }