I am trying to implement a simple form with Angular 2 and .Net Core.
My .Net Core controller is like this-
[HttpPost("[action]")]
public async Task<IActionResult> Add(string name, string dob)
{
    Profile profileToSave = new Profile
                                {
                                    Name = name,
                                    DateOfBirth = DateTime.Now
                                };
    _context.Profile.Add(profileToSave);
    await _context.SaveChangesAsync();
    return Ok(profileToSave);
}
It is working perfectly like this (with Postman)-
I am trying to use this API in Angular 2 Component like this-
public addProfileSubmit(event,name,dob): void
{
    event.preventDefault();
    var data: {
        name: string;
        dob: string;
    } = {
            name: name,
            dob: dob
        };
    console.log(data);
    let opts: RequestOptions = new RequestOptions();
    opts.method = RequestMethod.Post;
    opts.headers = new Headers({ 'Content-Type': 'application/json' });
    this.http.post(this._addProfileUrl, JSON.stringify(data), opts)
        .subscribe(res => {
            alert("Profile Added Successfully");
            //this.router.navigate(['./SomewhereElse']);
            console.log(res);
            this.reloadAllData();
            this.hideAddProfileModal();
        },
        (err) => {
            console.log(err);
            alert("An Error Occured !!");
        }
    );
}
By this, I am getting a request like this (from Chrome Developer Tool)-
So, I am creating a request with request payload, not Form Data.
I need to create the request with form data.
Can anyone please help to create a proper post request with Angular 2?
Thanks in advance for helping.


 
     
     
    