示例#1
0
        protected void PopulateModelSelectLists(List <Category> categories, List <Author> authors)
        {
            //Categories List
            CategoriesSelectList = categories
                                   .Select(x => new SelectListItem()
            {
                Value    = x.Id.ToString(),
                Text     = x.Name,
                Selected = SelectedCategories != null && SelectedCategories.Contains(x.Id)
            });

            //Authors list
            AuthorsSelectList = authors
                                .Select(x => new SelectListItem()
            {
                Text     = x.FirstName + " " + x.LastName,
                Value    = x.Id.ToString(),
                Selected = x.Id == AuthorId
            });
        }