后端不能像空值那样看前端帖子

时间:2017-10-22 12:00:43

标签: c# angularjs

我有c#controller

[EnableCors("AllowSpecificOrigin")]
        [Route("AddCar"), HttpPost]
        public async Task<CarStatus> AddCar(Car car)
        {
            return _carService.AddCar(car);
        }

和Angular服务

  AddCar(addCarModel: CarModel): Promise<CarStatus>{

const headers =  new Headers({ 'Content-Type': 'application/json'});
return this.http.post("http://localhost:54116/AddCar", JSON.stringify({RegistrationNumber : addCarModel.RegistrationNumber, TypeOfCar: addCarModel.TypeOfCar, Model: addCarModel.Model,
YearOfProduction: addCarModel.YearOfProduction, Power: addCarModel.Power, vinNumber: addCarModel.VinNumber, Factory: addCarModel.Factory, CarReviewDate: addCarModel.CarReviewDate ,
OcEndDate: addCarModel.OcEndDate, Insurer: addCarModel.Insurer,UdtElevatorReviewWhen : addCarModel.UdtElevatorReviewWhen, UdtElevatorReviewFrom: addCarModel.UdtElevatorReviewFrom, 
 TachografReviewWhen: addCarModel.TachografReviewWhen, TachografReviewFrom: addCarModel.TachografReviewFrom,FaultList: null ,Owner: addCarModel.Owner}), { headers: new Headers({ 'Content-Type': 'application/json' }) }).toPromise().
 then(response => {
  var y = response.json();
  return y;

}); 和AddCar.ts

import { Component, OnInit } from '@angular/core';
import { CarService } from '../../services/car.service';
import { NgForm } from "@angular/forms";

@Component({
  selector: 'app-add-car',
  templateUrl: './add-car.component.html',
  styleUrls: ['./add-car.component.css']
})
export class AddCarComponent implements OnInit {

  constructor(private carService: CarService) { }

  ngOnInit() {
  }

  onSubmit(form: NgForm): void {
    console.log(form.value);
    this.carService.AddCar(form.value);
  }
}

My Angular CarModel

export class CarModel{
    RegistrationNumber: string;
    CarReviewDate : Date;
    Factory: string;
    Insurer: string;
    Model : string;
    OcEndDate: Date;
    Owner : string;
    Power : number;
    TypeOfCar: string;
    YearOfProduction: number;
    VinNumber: string;
    UdtElevatorReviewFrom: Date;
    UdtElevatorReviewWhen: Date;
    TachografReviewFrom: Date;
    TachografReviewWhen: Date;
    FaultList : Fault[];
}

我的c#汽车模型

public class Car
    {
        [Key]
        public string RegistrationNumber { get; set; }
        public string TypeOfCar { get; set; }
        public string Model { get; set; }
        public int YearOfProduction { get; set; }
        public int Power { get; set; }
        public string VinNumber { get; set; }
        public string Factory { get; set; }
        public DateTime CarReviewDate { get; set; }
        public DateTime OcEndDate { get; set; }
        public string Insurer { get; set; }
        public DateTime? UdtElevatorReviewWhen { get; set; }
        public DateTime? UdtElewatorReviewFrom { get; set; }
        public DateTime? TachografReviewWhen { get; set; }
        public DateTime? TachografReviewFrom { get; set; }
        public List<Fault> FaultList { get; set; }
        public string Owner { get; set; }

在后端我有braekpoint和连接是好的,但发送汽车的所有值都是空的。为什么?我该如何解决这个问题? 链接到项目https://github.com/BialekM/TransportApp 网络状态https://imgur.com/QRZ4KJw C#告诉我所有的值都是null,没有2个datetime wchick不能为null

0 个答案:

没有答案