コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Brand,Model")] Printer printer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(printer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(printer));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
コード例 #3
0
        [HttpPost] //post method
        public async Task <IActionResult> Create([Bind("Id,Name")] Book book)
        {
            if (ModelState.IsValid)
            {
                _db.Add(book);                           //add data to Book table
                await _db.SaveChangesAsync();            //wait for database response

                return(RedirectToAction(nameof(Index))); // redirect to index
            }

            return(View(book));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id, Name, Brand, Model")] Printer printer)
        {
            if (ModelState.IsValid)
            {
                _db.Add(printer);                        //add data to Printer table
                await _db.SaveChangesAsync();            //wait for database response

                return(RedirectToAction(nameof(Index))); // redirect to index
            }

            return(View(printer));
        }