2

asp.net core 2.2 httpget method can't deserialize array of enums and returns

"title":"Unsupported Media Type","status":415,"

maybe someone can advice something

 [HttpGet("find")]
    public async Task<ActionResult<IEnumerable<SomeDTO>>> Find(SomeEnum []enums )
    {
       ....some service calls here
        return Ok(result);
    }

input like .../find?enums=1&enums=2

2
  • Share your code and input to the api. Commented Jan 21, 2020 at 10:53
  • added some code and used url pattern Commented Jan 21, 2020 at 11:16

1 Answer 1

2

You can explicitly add [FromQuery] attribute to your parameter, like:

[HttpGet("find")]
public async Task<ActionResult<IEnumerable<SomeDTO>>> Find([FromQuery] SomeEnum[] enums )
{
    // ...some service calls here
    return Ok(result);
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you really much!!! i've been surfing in web for about 2 hours and haven't find any solution. Where did you find that solution? maybe some good book or msdn ?
@Nakipatop sorry, but I cannot point you to docs, but if you try to debug your app, you will find that asp.net selects Body model binder (from request body), which checks content type of your request (which is empty), that why you see unsupported content type, and add attribute to force asp.net to use query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.