英文:
Bind property to another input name in nested array property
问题
以下是翻译好的部分:
The data in JSON format is sent to api endpoint.
Data sample:
{
"templateId": "dc15e4d1-ccbd-4581-a819-5b7f90b32cc5",
"name": "abc",
"steps": [
{
"id": "34b4f406-120e-4d80-8018-6c780c80a6c4",
"visible": false
}
]
}
Api gets data in this format:
public class TemplateRequest {
public Guid TemplateId { get; set; }
public string Name { get; set; }
public StepRequest[] Steps { get; set; }
}
StepRequest class:
public class StepRequest {
[ModelBinder(Name = "id")]
public Guid StepId { get; set; }
public bool? Visible { get; set; }
}
The JSON has id
key instead of stepId
, but I can't get it in controller.
When I check, the StepId
is always an empty Guid.
What is wrong here, why the StepId
property is not having the value from id
key?
英文:
The data in JSON format is sent to api endpoint.
Data sample:
{
"templateId": "dc15e4d1-ccbd-4581-a819-5b7f90b32cc5",
"name": "abc",
"steps": [
{
"id": "34b4f406-120e-4d80-8018-6c780c80a6c4",
"visible": false,
}
]
}
Api gets data in this format:
public class TemplateRequest {
public Guid TemplateId { get; set; }
public string Name { get; set; }
public StepRequest[] Steps { get; set; }
}
StepRequest class:
public class StepRequest {
[ModelBinder(Name = "id")]
public Guid StepId { get; set; }
public bool? Visible { get; set; }
}
The JSON has id
key instead of stepId
, but I can't get it in controller.
When I check, the StepId
is always an empty Guid.
What is wrong here, why the StepId
property is not having the value from id
key?
答案1
得分: 0
是的,就像 @daremachine 说的那样,这是NewtonSoft和 JsonProperty(PropertyName = "id")
有帮助。
英文:
Yes, like @daremachine said, it was NewtonSoft and JsonProperty(PropertyName = "id")
helped.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论