Angular HTTP POST in ASP.Net MVC Application

This post explains how we can make an HTTP POST in Angular application, to an API which is exposed as a web service. This is a continuation of the previous example HTTP GET in Angular -Asp.Net MVC Application. You can download the source code from here. In the source code, please refer to 4_Angular_Http_POST project.

Edit app.module.ts and import FormsModule from angular/forms.

Below is the updated app.module.ts file.

Add a new file ‘add-employee.component.html’ in Angular\Employee folder. This is the template for add-employee component. The contents of the file is as below.

Specify the template url in add-employee component.

Navigate to Employee/AddEmployee link and you can see page.

Edit EmployeeAPIController and add HTTP Post method to save employee.

Add a new method for saveEmployee in employee.service.ts

Modify add-employee.component.ts and call employeeService to save new employee.

Navigate to Employee/Add Employee link. Enter employee details in the form and click on submit.

If everything goes well you get a Success message.

One comment on “Angular HTTP POST in ASP.Net MVC Application

Leave a Reply

Your email address will not be published. Required fields are marked *