示例#1
0
        public IActionResult Create()
        {
            // Get Post entity from database
            // Populate list of possible categories for post & add to model
            var categories      = _categoryFinder.FindAll();
            var categoryOptions = categories.Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            });

            // Add post & categories to ViewModel
            // Populate the view's model
            return(View(new CreateTicketModel
            {
                Categories = categoryOptions
            }));
        }
        public IActionResult Index()
        {
            var categories = _categoryFinder.FindAll();
            var viewModels = categories.Select(t => new CategoryListViewModel
            {
                Id   = t.Id,
                Name = t.Name
            }).ToArray();

            return(View(viewModels));
        }