【发布时间】:2020-09-16 11:28:56
【问题描述】:
我正在尝试将 Car 对象添加到我的数据库中,仅使用字符串就可以正常工作,但是当我尝试添加整数值时,该值在 Json 中被引用,因此变成了字符串。 这是我的 .Net Core 模型:
public class Car : Service
{
public string Description { get; set; }
public int Price { get; set; }
public string Options { get; set; }
}
这是我的创建处理程序
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
{
var car = new Car
{
id = request.id,
Name = request.Name,
Description = request.Description,
Price = request.Price,
Options = request.Options
};
_context.Cars.Add(car);
var success= await _context.SaveChangesAsync() > 0;
if(success) return Unit.Value;
throw new System.Exception("Problem saving changes");
}
create 处理程序同样适用于字符串,但是当我尝试发送整数值时,这是发送的 Json
{id: "f8aa6881-8a90-4510-9505-5471c1f9a656", name: "Mercedes AMG", description: "a", price: "800",…}
description: "a"
id: "f8aa6881-8a90-4510-9505-5471c1f9a656"
name: "Mercedes AMG"
options: "a"
price: "800" //This is the value creating the problem
price:{}; The JSON value could not be converted to System.Int32
请问我如何确保该值作为整数传递?感谢您的帮助。
【问题讨论】:
标签: .net json reactjs string api