Save Form Data to Database using Model in ASP.NET CORE


In this chapter you will learn

  1. How to create Database in ASP.NET Core?
  2. Store Connection String in appsettings.json file
  3. How to retrieve connection string from appsettings.json file?
  4. Make model class to save data to database

Till now, you have learned how to make model class in asp.net core and how to connect it with controller. In this chapter you will learn whole package including creating model and saving data to database. This chapter is going to be quite interesting because once you complete this chapter you will be able to apply your own logic to database and project. So, study this chapter thoroughly to understand basic concept of working with database in ASP.NET Core.


Here, I am creating a New Project UserProfile, that will ask user details and save into database.


Design View Page

Step 2. Add a View Page Profile.cshtml under Home folder and add the following code.

Create Database and Table

Step 3. Create UserProfile Database to save these details. Go to View