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
Post a Comment