コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("ID,Title,RelaseDate,Genre,Price,Rating")] Movie moive)
        {
            if (ModelState.IsValid) // this ModelState.IsValid checks whether there are any valadiaion errors. by callings this method it evaluates any validation attributes that have been applied to the object.
            {
                _context.Add(moive);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(moive));
        }