Learning ASP.NET Core MVC Programming by Ragupathi Mugilan T. S

Learning ASP.NET Core MVC Programming by Ragupathi Mugilan T. S

Author:Ragupathi, Mugilan T. S. [Ragupathi, Mugilan T. S.]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2016-11-15T16:00:00+00:00


In the preceding GET Index action method, we are creating the ViewModel object and passing it to the View.

The following code uses POST Index action method:[HttpPost] public IActionResult Index(EmployeeAddViewModel employeeAddViewModel) { using (var db = new EmployeeDbContext()) { db.Employees.Add(employeeAddViewModel.NewEmployee); db.SaveChanges(); //Redirect to get Index GET method return RedirectToAction("Index"); } }

We get the NewEmployee property in the ViewModel, which contains the information on the user. Save it to the database. Once we save the employee information to the database and we redirect the control to the GET Index action method, the GET Index action method will again show the form to enter the employee information and the list of employees in table format.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.