コード例 #1
0
ファイル: HomeController.cs プロジェクト: LeoLcy/MVC6Recipes
        public IActionResult Index()
        {
            var model = new GuitarBrandViewModel();
            model.Brands = _items;

            return View(model);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: LeoLcy/MVC6Recipes
        public IActionResult Index(GuitarBrandViewModel model)
        {
            model.Brands = _items;
            if (model.SelectedBrandId != 0)
            {
                model.SelectedBrand = (from b in _items
                                       where b.Value == model.SelectedBrandId.ToString()
                                       select new GuitarBrand {
                                           GuitarBrandId = int.Parse(b.Value),
                                           Name = b.Text }).FirstOrDefault();

            }

            return View(model);
        }