public ActionResult Index(int?categoryId) { ToDoItemsDb db = new ToDoItemsDb(Properties.Settings.Default.ConStr); ToDoItemsListViewModel vm = new ToDoItemsListViewModel(); if (categoryId == null || categoryId == 0) { vm.ToDoItems = db.GetAll(); } else { vm.ToDoItems = db.GetItemsForCategory(categoryId.Value); } vm.Categories = db.GetCategories(); vm.SelectedCategory = categoryId; return(View(vm)); }