I want to add another dropdownlist. The below code works for one dropdown, but how would I add one for Categories?
public ActionResult Create()
{
var ddl = new Users();
ddl.DropDowns = userRepository.Getddl("Departments").Select(c => new SelectListItem
{
Value = c.DropdownID.ToString(),
Text = c.DropdownText
});
ViewData["ListofProfiles"] = new SelectList(ListofProfiles, "Value", "Text");
return View(ddl);
}
Try to avoid the
ViewDataapproach.Switch to Strongly typed way of doing this. Add another property to your View Model to carry one more dropdown itemsNow set the collection in your
GETactionWhere
GetCountryItemsandGetProfileItemsare 2 methods which returns a list of SelectListItem objects for countries and Profiles from db.Do not make your controllers FAT. Just keep it simple and clean. Move away your code which fetch data from repository to a different layer. Easy to read and maintain 🙂
And in your strongly typed view,