JSON值无法转换为System.Int64



我的post方法出现了这个错误

[HttpPost]
public async Task<ActionResult<Order>> PostOrder(Order order)
{
...
}

这是我的Order和OrderItem模型

public partial class Order
{
public Order()
{
OrderItems = new HashSet<OrderItem>();
}
public long OrderId { get; set; }
public string OrderNo { get; set; }
public int? CustomerId { get; set; }
public string Pmethod { get; set; }
public decimal? Gtotal { get; set; }
public virtual Customer Customer { get; set; }
public virtual ICollection<OrderItem> OrderItems { get; set; }
}
public partial class OrderItem
{
public long OrderItemId { get; set; }
public long? OrderId { get; set; }
public int? ItemId { get; set; }
public int? Quantity { get; set; }
public virtual Item Item { get; set; }
public virtual Order Order { get; set; }
}

这是角的模型

export class Order {
orderId: number
orderNo: string
customerId: number
pMethod: string
gTotal: number
}
export class OrderItem {
orderItemId:number;
orderId:number;
itemId:number;
quantity:number;
itemName: string;
price: number;
total: number;
}

这是我的orderService

formData:Order;
orderItems:OrderItem[];
apiUrl =environment.apiUrl;
constructor(private http:HttpClient) { }
saveOrUpdateOrder() {
var body = {
...this.formData,
OrderItems: this.orderItems
};
return this.http.post<any>(this.apiUrl + '/Orders', body);
}

当我尝试

var body = JSON.stringify({
...this.formData,
OrderItems: this.orderItems
});

出现此错误&"不支持的媒体类型&";

我尝试添加Microsoft.AspNetCore.Mvc.NewtonsoftJson库,它不工作我添加了IntToConverter类,但它也不起作用。请帮帮我

不需要调用JSON.Stringify.

将TypeScript模型扩展到
export class Order {
orderId: number
orderNo: string
customerId: number
pMethod: string
gTotal: number
orderItems: OrderItem[] //include this
}

然后在你的apiCall。this.formData.orderItems = this.orderItems

return this.http.post<Order>(this.apiUrl + '/Orders', formData);

相关内容

  • 没有找到相关文章

最新更新