0

Here is a sample of basic web API:

public class MyController : ApiController
{
    public MyEnum Get()
    {
        return MyEnum.One;
    }

    public void Post(MyEnum value)
    {
    }

    public void Put(int value)
    {
    }
}

public enum MyEnum
{
    One = 1,
    Two,
    Three,
    Four,
    Five
}

Here are the queries with an expected behavior:

  • POST /api/My?value=1 → 200
  • PUT /api/My?value=1 → 200
  • PUT /api/My?value=1,2 → 400

Here is the query with an unexpected behavior:

  • POST /api/My?value=1,2 → 200 with value = 3

I don't understand why.
I expected an 400 error but I get a 200 with a wrong value.
Could someone explain me why I get this result?

Nicolas
  • 6,289
  • 4
  • 36
  • 51
  • A comma is not really a good way to distinguish different parameters. I think it just tries to use it as one number. Even though 3 is a mistery to me – Remy Nov 14 '19 at 16:13
  • Possible duplicate of [Best practice for passing enum params in Web API](https://stackoverflow.com/questions/39789818/best-practice-for-passing-enum-params-in-web-api) – Andrei Dragotoniu Nov 15 '19 at 15:14

0 Answers0