当我尝试将数据发送到api Asp.net时,我在控制台400上发现错误(错误请求) 但是,当我在邮递员流程上将相同的婴儿车发送到同一端点时,成功完成了操作,并且当我尝试通过Http从同一数据库获取信息时,当我将数据发送到前端时,前端角度问题上的数据加载正确了
表单代码:
<form #form="ngForm" autocomplete="off" (submit)="insertRecord(form)">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Course Name</label>
<input type="text" class="form-control border-input" placeholder="Enter Course Name (Geographic - Math ..... " name="DepartmentId" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Course Name</label>
<input type="text" class="form-control border-input" placeholder="Enter Course Name (Geographic - Math ..... " name="Name" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control border-input" placeholder="Enter Course Name (Geographic - Math ..... " name="Image">
</div>
</div>
</div>
<div class="row text-center">
<div class="col-md-4">
<button type="submit" class="btn btn-info btn-fill btn-wd" [disabled]="form.invalid"><i class="ti-plus"></i> Save and New</button>
</div>
<!-- <div class="col-md-4">
<button type="submit" class="btn btn-info btn-fill btn-wd"><i class="ti-save"></i> Save and Exit</button>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-info btn-fill btn-wd" [disabled]="form.invalid"><i class="ti-close"></i> Reset Field</button>
</div> -->
</form>
在ts上插入记录功能:
insertRecord(form: NgForm) {
this.service.addNew().subscribe(
res => {
this.resetForm(form);
this.toastr.success('Submitted successfully', 'Subject Detail Register');
this.service.refreshList();
},
err => {
console.log(err);
}
)
}
和服务:
addNew() {
return this.http.post(this.rootURL + '/Subjects/AddSubject', this.formData);
}
错误::
POST https://localhost:5001/api/Subjects/AddSubject 400 (Bad Request)