在Angle 8和ASP.NET Core 3.0中将Value null转换为类型'system.int32'时出错

时间:2019-12-31 01:16:25

标签: c# angular asp.net-core-webapi

请尝试从客户端创建Vehicle,但始终收到此错误将Value null转换为类型'system.int32''Id'时出错。用邮递员创建一辆车很完美。

这些是我的vehicle.component.ts代码

from tkinter import *

def draw_curve():
    from math import cos, exp
    w, h, colors = width//2, height//2, ('#0F0','#F00','#00F')
    for n in range(3): # loop over curves
        xa, ya, xb, yb = 0, h, 0, h # initial position for each curve
        for x in range(w+1): # loop over horizontal axis
            t = 2*x/w - 1 # parameter t moves over range [-1,1]
            if n == 2: # draw damped cosine wave
                xa, ya, xb, yb = xb, yb, 2*x, h + h*exp(-5*t*t)*cos(25*t)
            elif n == 1: # draw negative bell curve
                xa, ya, xb, yb = xb, yb, 2*x, h + h*exp(-5*t*t)
            elif n == 0: # draw positive bell curve
                xa, ya, xb, yb = xb, yb, 2*x, h - h*exp(-5*t*t)
            canvas.create_line(xa, ya, xb, yb, width=1, fill=colors[n])    

def draw_grid():
    steps = 20 # number of grid steps
    dw, dh = width/steps, height/steps # horizontal and vertical steps
    for n in range(steps):
        canvas.create_line(0, n*dh, width, n*dh, width=1, dash=(1,1)) 
        canvas.create_line(n*dw, 0, n*dw, height, width=1, dash=(1,1))
    canvas.create_rectangle(2, 2, width-1, height-1, width=1)

width, height = 800, 600
win = Tk()
canvas = Canvas(win, width=width, height=height)
canvas.pack(padx=5, pady=5)
draw_grid()
draw_curve()
win.mainloop()

和Vehicle.ts

 makes:any=[];
 models:any[];
 features: any=[];
 vehicle: SaveVehicle={
id:0,
makeId:0,
modelId:0,
features:[],
isRegistered:false,
contact: {
  name:'',
  phone:'',
  email:''

 }
};

 constructor(private route:ActivatedRoute,private router:Router,
 private makeService:MakeService,private toastr:ToastrService) {
  route.params.subscribe(p=>{
    this.vehicle.id= +p['id'];
  });
 }

 ngOnInit() {
 var sources = [
  this.makeService.getMakes(),
  this.makeService.getFeatures()
  ];

if(this.vehicle.id){
  sources.push(this.makeService.getVehicle(this.vehicle.id));
}

forkJoin(sources).subscribe(data=>{
  this.makes = data[0];
 this.features=data[1];
 if(this.vehicle.id){
  this.setVehicle(<any>data[2]);
  this.populateModels();
 }



},
err=>{
  if(err.status==404){
    this.router.navigate(['/home']);
  }

})

 }
 private populateModels(){
 var selectedMake = this.makes.find(m=>m.id==this.vehicle.makeId);

 this.models = selectedMake? selectedMake.models:[];
  }
 private setVehicle(v:Vehicle){
  +this.vehicle.id;
  this.vehicle.id=v.id;
  this.vehicle.modelId=v.model.id;
 this.vehicle.makeId=v.make.id;
 this.vehicle.isRegistered=v.isRegistered;
 this.vehicle.contact=v.contact;
 this.vehicle.features=_.pluck(v.features,'id');

 }

  submit(){

  if(this.vehicle.id){
  this.makeService.updateVehicle(this.vehicle).subscribe(
    x=>{
      this.toastr.success('Vehicle Updated successfully','Success');
    },
    err=>{
      console.log(err);
    }
    );
    }else{
     console.log(this.vehicle);
    this.makeService.createVehicle(this.vehicle).subscribe(
    x=>{console.log(x)
    this.toastr.success('Success', 'Vehicle created successfully');},
    err=>{
      console.log(err);
     }

     );
   }

请尽快帮助我解决此问题。目前正在获取空车辆ID。 预先感谢

0 个答案:

没有答案