Click here to Skip to main content
15,792,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have two solutions
1. ASP.NET web application(.Net framework)(Web Api)
2. ASP.NET Core application(.Net Core)

in Visula Studio 17.

import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions, RequestMethod } from '@angular/http';
import 'rxjs/Rx';

import { Employee } from '../models/Employee'

export class EmployeeManagementService {
    constructor(private http: Http) {

    addEmployeeDetails(employeeDetails: Employee) {

        var obj = {Firstname: employeeDetails.FirstName, LastName: employeeDetails.LastName, PhoneNumber: employeeDetails.PhoneNumber};

        let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' });
        let options = new RequestOptions({ method: RequestMethod.Post, headers: headers });

        let emp = JSON.stringify({ obj });

        return'http://localhost:xyz/api/employee-management/create-employee', emp, options)
            .map((res: Response) => res.json())

public class EmployeeManagementApiController : ApiController
        //Create Employee
        public IHttpActionResult CreateEmployee([FromBody]Employee emp)
            EmployeeService service = new EmployeeService();
            var serv = service.CreateEmployee(emp);

            if (serv.status == 1)
                return Ok(emp);
                return new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.PreconditionFailed, serv.message));

Employee.ts file

   public class Employee
        public Guid Id { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string PhoneNumber { get; set; }

 export class Employee {
    FirstName: string;
    LastName: string;
    PhoneNumber: string;

My ts file is in on solution and my api is in another solution.
here am getting calls to my API but emp values are all null. Am i missing anything . Please help me out.

Thanks in advance

What I have tried:

same code i have tried with normal controller in same Solution ,
if i send single parameter values is passed to API controller.
Updated 16-May-17 0:12am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900