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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,CourseName,Description,Duration,Price")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,CourseId,InstructorId,StudentId")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]     = new SelectList(_context.Course, "Id", "Id", enrollment.CourseId);
            ViewData["InstructorId"] = new SelectList(_context.Set <Instructor>(), "Id", "Id", enrollment.InstructorId);
            ViewData["StudentId"]    = new SelectList(_context.Set <Student>(), "Id", "Id", enrollment.StudentId);
            return(View(enrollment));
        }