自定义模型绑定程序:无法绑定参数'xxx',因为它具有冲突的属性

SJM*_*Man 2 model-binding custom-model-binder asp.net-web-api asp.net-web-api2

我正在使用自定义模型绑定器,以便在我的模型绑定中放置一些自定义逻辑.

这是我的DTO:

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; }
}
Run Code Online (Sandbox Code Playgroud)

步骤DTO:

public class StepDto
{
    public int Id { get; set; }

    [MaxLength(100)]
    public string Description { get; set; }

    public StepType StepType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

ResourceDTO:

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; }
}
Run Code Online (Sandbox Code Playgroud)

ResourceType枚举在哪里(现在只有1作为值.)

我尝试使用此链接创建自定义模型绑定器.

这是我的API Action方法签名:

    [HttpPut]
    [Route("datacapture/{activityId}/tasks")]
    [Authorize]
    public async Task<IHttpActionResult> UpdateAllDataCaptureActivities(int activityId, [FromBody][ModelBinder] TaskDto tasks)
     {
      ...
     }
Run Code Online (Sandbox Code Playgroud)

我在调用API时收到以下错误:

"Message": "An error has occurred.",
  "ExceptionMessage": "Can't bind parameter 'tasks' because it has conflicting attributes on it.",
  "ExceptionType": "System.InvalidOperationException",
Run Code Online (Sandbox Code Playgroud)

Naz*_*zyk 10

请勿同时使用[FromBody]和[ModelBinder].