public async Task <IActionResult> Create([Bind("Id,Name,Address,Phone")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Example #2
0
        public async Task <IActionResult> Create(
            [Bind("CourseId,Sid,FutureEnroll")] Enrollment enrol)
        {
            try {
                if (ModelState.IsValid)
                {
                    _context.Add(enrol);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Create)));
                }
            }

            catch (DbUpdateException exception)
            {
                return(RedirectToAction("Create", new { msg = "Error PK Violation" }));
            }


            return(View(enrol));
        }