Introduction
In this article, I have explained how to create a WEBAPI POST method to retrieve data from an SQL database using ASP.NET MVC Application.
Open SQL Management Studio then create a new table and write the stored procedure for the table.
Column name and datatype of table based on your requirement.
![data table]()
Once you have successfully created the SQL store procedure then Create a new MVC WebAPI Application using visual studio.
provide the project name and project location.
![]()
Choose Empty project then select the MVC and WEB API options from the right side core references section.
![create New application]()
Now the project has been created successfully.
![project success]()
Once the project has been created then Right click on the Models folder, choose to add, and click New item.
Add the class file to the Models Folder.
![AddClassFile]()
From the C# node then choose the class definition and provide the class file name UserEntity.cs.
Once we added the class file to our project solution.
![classDefinition]()
Use the below code in UsersEntity.cs file.
Likewise create a new logger.cs and ErrorDetails.cs class file to capture the logs and error details in the Models folder.
Use the below code in Logger.cs file.
Use the below code in ErrorDetails.cs file.
Then add the controller to the Controller folder.
Right Click on the Controller folder, choose to add, and click Controller.
Click the MVC empty read and write controller file.
![mvc]()
![select Controller]()
Then give the controller name based on your requirement.
![AddController]()
Once the Controller has been created successfully, we can write the Controller methods in the controller.
Use the below code in the controller.
Once we ran the application, we got the output like the below screenshot.
![output]()
Sharing is Caring!!..