public class TaskDto
{
public int Id { get; set; }
[MaxLength(100), Required]
public string Name { get; set; }
public List<StepDto> Steps { get; set; }
public List<ResourceDTO> Resources { get; set; }
}
步骤DTO:
public class StepDto
{
public int Id { get; set; }
[MaxLength(100)]
public string Description { get; set; }
public StepType StepType { get; set; }
}
资源DTO:
public class ResourceDTO
{
public int Id { get; set; }
[MaxLength(250), Required]
public string Title { get; set; }
[Required]
public string Link { get; set; }
public string MetaTagUrl { get; set; }
[Required, Range(1, 1)]
public ResourceType ResourceType { get; set; }
}
其中ResourceType
是一个枚举(目前只有一个值1)。
我尝试使用此链接创建自定义模型绑定器。
这是我的API Action方法签名:
[HttpPut]
[Route("datacapture/{activityId}/tasks")]
[Authorize]
public async Task<IHttpActionResult> UpdateAllDataCaptureActivities(int activityId, [FromBody][ModelBinder] TaskDto tasks)
{
...
}
在调用API时,我遇到了以下错误:
"Message": "An error has occurred.",
"ExceptionMessage": "Can't bind parameter 'tasks' because it has conflicting attributes on it.",
"ExceptionType": "System.InvalidOperationException",