Step 2 : Create Web Application
- "Start" -> "All Programs" -> "Microsoft Visual Studio 2010".
- "File" -> "New Project" -> "C#" -> "Empty Project" (to avoid adding a master page).
- Provide the website a name such as "InsertingFormDataUsingWebAPI" or another as you wish and specify the location.
- Then right-click on the Solution Explorer -> "Add New Item" -> Add Web Form.
- Drag and drop three text boxes and one Button onto the <form> section of the Default.aspx page.
Step 3 : Create Property Class
Step 4: Add Web API Controller Class
Step 5: Create Repository Class
The entire EmpRepository class file will be as follows:
Step 6: Create Post method
You have seen that the preceding EmpController class is inherited from the ApiController class and we have created the method AddEmployee that the calls EmpRepository class method named AddEmployees.
Step 7: Configure ASP.Net Web API routing
Step 8: Call the Register method
Step 9: Call ASP.Net Web API Controller method
Now enter some records into the preceding fields and click on the Save button. The following message will be shown.
Now you have seen how the records are inserted into the database using the ASP.Net Web API with Web Forms.
- For detailed code sample file i will upload soon.
- Do a proper validation such as date input values when implementing.
- Make the changes in the web.config file depending on your server details for the connection string.