request in angular app returns status 400

I’m trying to send a post request to an asp.net core backend in order to validate an input name, but get status 400 bad request.

This is the controller:

[Route("api/masterdata/general/companies")]
[ApiController]
public class CompanyController : Controller
{
    private DataContext DataContext;

    public CompanyController(DataContext dataContext)
    {
        DataContext = dataContext;
    }

    [HttpGet("{id}")]
    public Company GetCompany(long Id)
    {
        return DataContext.Companies.Find(Id);
    }

    [HttpGet]
    public IEnumerable<Company> GetCompanies()
    {
        return DataContext.Companies;
    }

    [HttpPost("validatename/{name}")]
    public JsonResult ValidateName(string name)
    {
        IEnumerable<Company> companies = DataContext.Companies;

        bool isValid = !companies.Any(c => Common.CleanName(c.Name) == Common.CleanName(name));

        return Json(isValid);
    }
}

And this is the corresponding service call in the angular app:

  validateName(name: string): Observable<any> {
    return this.http.post<boolean>("api/masterdata/general/companies/validatename/" + name, null);
  }

Why get I bad request? The GetCompanies api call is f.e. reached and working fine.

Thanks.

%d bloggers like this: