Custom Model binder :Can't bind parameter 'xxx' because it has conflicting attributes on it

Viewed 1224

I am using a custom model binder in order to put some custom logic in my model Binding.

Here's my DTOs:

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; }
}

Step DTO:

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

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

    public StepType StepType { get; set; }
}

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; }
}

Where ResourceType is an enumeration (only has 1 as value for now.)

I tried creating a custom model binder using this link.

Here's my API Action method signature:

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

I am getting the following error on calling the API:

"Message": "An error has occurred.",
  "ExceptionMessage": "Can't bind parameter 'tasks' because it has conflicting attributes on it.",
  "ExceptionType": "System.InvalidOperationException",
1 Answers
Related