Backend - ASP NET CORE 5. Frontend - Angular 2. The logic is for a simple Search through a list in the database. The Issue that I am encountering is during a PUT (also tried a POST) request. The issue is the following : 0: "Unexpected character encountered while parsing value: a. Path '' (Status code 400). The Api works correctly (tested with postman), but when I try to make the request through the angular app I encounter that issue. Note: Doesn't reach the method in the Controller it seems. Where it seems to be the problem ?
Thank you.
Angular:
TS Component:
searchBar = new FormControl('',[Validators.maxLength(50),Validators.required])
getSearchedJobs(){
console.log(this.searchBar.value)
this.informationService.getCompaniesSearchedByUser(this.searchBar.value).subscribe(response=>{
this.jobs = response;
});
}
HTML Component:
<form class="form-group row ml-2" (ngSubmit)="getSearchedJobs()">
<button type="submit" class="btn btn-primary">Search</button>
<div class="ml-2"><input type="search" [formControl]="searchBar" class="form-control"></div>
</form>
Service Component:
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
getCompaniesSearchedByUser(model: any) {
console.log(model);
return this.http.put(this.baseUrl + "information/search-jobs-setbyusers/", model,this.httpOptions);
}
Seems that if I don't add the content-type will give me Status Code Error 415
NET:
Controller:
[HttpPut("search-jobs-setbyusers")]
public async Task<ActionResult<IEnumerable<GetCompaniesJobsLinksDto>>>SearchJobs([FromBody]SearchJobsDto searchJobsDto)
{
if(String.IsNullOrEmpty(searchJobsDto.SearchJob))
{
return NotFound("Please try to add something in the search bar !");
}
var jobs = await _informationRepository.SearchJob(searchJobsDto.SearchJob.ToLower());
if(!jobs.Any())
{
return NotFound("Nothing was found !");
}
return Ok(jobs);
}
}
SearchJobsDto: (contains only a string)
[MaxLength(50)]
public string SearchJob { get; set; }