public async Task <IActionResult> Create([Bind("CourseId,CourseName,CourseProf")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                TempData["message"] = $"{course.CourseName} has been added";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("TextbookId,Name,Author,Price,CourseId")] Textbook textbook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(textbook);
                await _context.SaveChangesAsync();

                TempData["message"] = $"{textbook.Name} has been added";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"] = new SelectList(_context.Course, "CourseId", "CourseId", textbook.CourseId);
            return(View(textbook));
        }