public IActionResult Add() { TodoItemIndexModel model = new TodoItemIndexModel(); model.TemplateItem = new TodoItem(); model.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>(); foreach (String s in this.context.Categories) { model.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Text = s, Value = s }); } return(this.View(model)); }
public TodoItemIndexModel GetTodoItems() { TodoItemIndexModel model = new TodoItemIndexModel(); model.TemplateItem = new TodoItem(); model.TodoItems = this.context.TodoItems.ToList(); model.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>(); foreach (String s in context.Categories) { model.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Text = s, Value = s }); } return(model); }
public IActionResult Add(TodoItemIndexModel item) { if (ModelState.IsValid) { this.context.TodoItems.Add(item.TemplateItem); return(RedirectToAction("Index")); } else { item.DropdownCategories = new List <Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>(); foreach (String s in this.context.Categories) { item.DropdownCategories.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem() { Text = s, Value = s }); } return(this.View(item)); } }
public IActionResult Index() { TodoItemIndexModel model = GetTodoItems(); return(this.View(model)); }