public ActionResult Create(CreateVM vm) { try { // TODO: Add insert logic here return RedirectToAction("Index"); } catch { return View(); } }
// GET: Products/Create public ActionResult Create() { var categories = new List<Category>() { new Category{Id = 1, Name = "Electronics"}, new Category{Id = 2, Name = "Beverages"} }; var vm = new CreateVM { // Anything that you can iterate over, you can pass to a select list. // Use Id property of Category to represent the data value, and the Name property to represent the label value Categories = new SelectList(categories, "Id", "Name") }; return View(vm); }