Having trouble passing a payload using Typescript service in an http.post request
Here is my TypeScript 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 was not saved"));
}
The URL to edit is mentioned as:
private UrlToEdit = '/Home/Edit';
However, even though the value is being sent to the service, the C# controller does not appear to be triggered. Here's the controller 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;
}