My ViewModel or Dto is always null at my server side when i send it for example to my Put Method
Here is my client side method
update(company: Company) {
return this.apiService.put(`${this.path}/${company.id}`,
company);
}
Put method in apiService
put(path: string, body): Observable<any> {
debugger;
this.setBearerHeader();
console.log('Http Post Observable: ', path, body);
let url = `${this.baseUrl}${path}`;
let request = new Request({
url: url,
headers: this.headers,
method: RequestMethod.Put,
body: body
});
return this.http.request(request)
.catch(this.handleError)
.map(res => res.json())
};
And my server side model in side which my dto is always null. Is it always required to use [FromBody]?
[HttpPut("{id}")]
public async Task<IActionResult> Put(string id,ViewModel dto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
if (id != dto.Id)
{
return BadRequest();
}
}
catch (Exception ex)
{
throw;
}
}