I stumbled upon a problem. I got an Angular 5 website and a backend based on C# WebApi.
In my webiste i got a component that is suppouse to send a post request to backend adding new entity to DataBase. Unfortunatelly it doesn't send a request or it isn's recieved on backend.
bet.component.ts
import {Injectable} from '@angular/core';
import {Service} from './service';
import {Http, Headers, RequestOptions, Response} from '@angular/http';
import {AppConfig} from '../app-config';
import {Bet} from '../models/bet';
@Injectable()
export class BetService extends Service {
private url = this.config.apiUrl + '/bet';
constructor(private http: Http, private config: AppConfig) {
super();
}
addBet(bet: Bet) {
return this.http.post(this.url + '/add', bet);
}
}
BetController.cs
using System;
using System.Threading.Tasks;
using FakeBet.API.DTO;
using FakeBet.API.Services.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FakeBet.API.Controllers
{
[Route("api/[controller]")]
public class BetController : Controller
{
private IBetService service;
public BetController(IBetService service)
{
this.service = service;
}
[HttpPost("[action]")]
public async Task<IActionResult> Add([FromBody] BetDTO bet)
{
try
{
await service.AddBetAsync(bet);
return Ok();
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}
Url is ok.
I tried to change bet.component.ts to
return this.http.post(this.url + '/add', bet).subscribe(x => console.log('test'));
and then the response is recieved on the backend side, but BetDto bet is null.
While bet is not null and the names of the properties are the same in the object in Angular and Api.
I also tried to send a request using a Postman and it went smooth. Here's how it looks. 
Can someone tell me where's my mistake? Cheers!
BetDTO
using System;
using FakeBet.API.Models;
namespace FakeBet.API.DTO
{
public class BetDTO
{
public Guid BetId { get; set; }
public string MatchId { get; set; }
public string UserId { get; set; }
public int BetOnTeamA { get; set; }
public int BetOnTeamB { get; set; }
}
}
bet.ts
export class Bet {
matchId: string;
userId: string;
betOnTeamA: number;
betOnTeamB: number;
}
Request using website: website request
Request using Postman:postman request
HttpClienthere. There's an Angular script that calls a Web API controller passing a JSON string in the body. If that body doesn't match the BetDTO class the parameter will be null. What doesBetDTOlook like? And btw the action method is namedAddso the URL should be/add, notaddBet