Trying to pass a payload via Typescript service to an http.post
My .ts code:
saveEdits(body: Object): Observable<Animal[]> {
let bodyString = JSON.stringify(body);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.UrlToEdit, body, options)
.map((res: Response) => res.json())
.catch((error: any) => console.log("Edited value did not been saved"));
}
Mention that
private UrlToEdit = '/Home/Edit';
Although the value is up to the service, C# controller not seems to fire up.. An here its code:
[HttpPost]
public async Task<Boolean> Edit([Bind(Include = "animalID,animalName,animalHabitat,animalClass")] Animal animal)
{
if (ModelState.IsValid)
{
db.Entry(animal).State = EntityState.Modified;
await db.SaveChangesAsync();
return true;
}
return false;
}