コード例 #1
0
        public async Task <IActionResult> Create([Bind("AuthorId,Name,Email,Phone")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("BlogID,Title,Created,LastModified,Post,AuthorId")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Author, "AuthorId", "AuthorId", blog.AuthorId);
            return(View(blog));
        }