这是我的问题
我在dataModel类A中有一个类
public class A
{
public string name { get; set; }
public string address { get; set; }
public string addressType { get; set; }
public A()
{
this.name = "";
this.address = "";
this.addressType = "";
}
}
在fron-end应用程序中,我有一个像这样的Json
{
name : "Jean",
address : "Golden Road St #122",
addressType : {
id: "ABC-ID-ADD",
description: "Street Adress"
}
}
在后端我有这个
[HttpPost]
[Route("save")]
public IHttpActionResult save([FromBody] A a)
{
// a.name == "Jean"
// a.address == "Golden Road St #122"
// but in this point a.addressType is null, but i want a.addressType == "ABC-ID-ADD"
return Ok();
}
有一种方法可以将“addressType” JSON的“id”属性映射到属性“addressType” A级?
提前致谢
答案 0 :(得分:-1)
更改前端的json
{
name : "Jean",
address : "Golden Road St #122",
addressType : "ABC-ID-ADD"
}