コード例 #1
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
ファイル: CatsController.cs プロジェクト: donat8/Mic
        public async Task <IActionResult> Create([Bind("CatId,Name,DateOfBirth,ShortDescription,LongDescription,Price,ImageUrl,ImageThumbnailUrl,IsPreferredCat,InStock,CategoryId")] Cat cat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", cat.CategoryId);

            return(View(cat));
        }