The JSON value could not be converted to System.String.
来源:7-2 【应用】创建旅游路线资源

minck
2021-12-03
请问老师,
1,这个提交错误是怎样产生的[
services.AddControllers().AddNewtonsoftJson(); 这样就可以解决转换了,不理解。
],
2, 空值为什么不能提交的?应该怎样做呢? ( public string? Fees { get; set; }) 这样?
TouristRouteForCreationDto:
[Required(ErrorMessage = “title 不可为空”)]
[MaxLength(100)]
public string Title { get; set; }
[Required]
[MaxLength(1500)]
public string Description { get; set; }
// 计算方式:原价 * 折扣
public decimal Price { get; set; }
//public decimal OriginalPrice { get; set; }
//public double? DiscountPresent { get; set; }
public DateTime CreateTime { get; set; }
public DateTime? UpdateTime { get; set; }
public DateTime? DepartureTime { get; set; }
public string Features { get; set; }
public string Fees { get; set; }
public string Notes { get; set; }
public double? Rating { get; set; }
public string TravelDays { get; set; }
public string TripType { get; set; }
public string DepartureCity { get; set; }
public IActionResult CreateTouristRoute([FromBody] TouristRouteForCreationDto touristRouteForCreationDto)
body:
{
“title”: "Test test demo demo ",
“description”: “【Test】demo”,
“originalPrice”: 11999.99,
“discountPresent”: 0.1,
“features”: “”,
“rating”: 3.5,
“travelDays”: 8,
“tripType”: 0,
“departureCity”: 0
}
400信息:
{
“errors”: {
“Fees”: [
“The Fees field is required.”
],
“Notes”: [
“The Notes field is required.”
]
},
“type”: “https://tools.ietf.org/html/rfc7231#section-6.5.1”,
“title”: “One or more validation errors occurred.”,
“status”: 400,
“traceId”: “00-bd5108f6b6ab5396ad17ce35cd232ff2-9ee6f4703eb5c812-00”
}
1回答
-
minck
提问者
2021-12-03
.net6 +visual studio code +EF mysql
00
相似问题