angular - Post method returns 404 in Asp.net core Web API Controller -


routes code below:

app.usemvc(routes =>             {                 routes.maproute(                     name: "default",                     template: "{controller=home}/{action=index}/{id?}");             }); 

controller code below :

// post api/values         [httppost]         public void post([frombody]employee employee)         {             employeemanager.createasync(employee);         } 

all other methods working except post method.

call angular component :

 onsubmit(employeeitems: any) {                 console.log(employeeitems);         this.getdata();         var headers = new headers();         headers.append('content-type', 'application/json; charset=utf-8');         this.http.post('api/employee/post', employeeitems, { headers: headers }).subscribe();         this.createemployeeflag = false;     } 

i tried postman, no luck.

your url , route templates not match

[route("api/[controller]")] public class employeecontroller : controller {      [httppost]     public async task<iactionresult> post([frombody]employee employee) {         await employeemanager.createasync(employee);         return ok();     } } 

and update calling url call default endpoint api/employee

onsubmit(employeeitems: any) {             console.log(employeeitems);     this.getdata();     var headers = new headers();     headers.append('content-type', 'application/json; charset=utf-8');     this.http.post('api/employee', employeeitems, { headers: headers }).subscribe();     this.createemployeeflag = false; } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -