I have this url: /api/v1/books?status=1
status is an optional query parameter and my API controller looks like this.
class BookController : ApiController
{
[HttpGet]
public JsonResult GetBooks(Status status)
{
// return statement
}
}
Status is an enum.
public enum Status
{
None = 0,
Available = 1,
NotAvailable = 2,
Modified = 3
Deleted = 4
}
Controller accepts 0,1,2,3,4,5,6,7 values, but rejects 8,9,10,11,... values(returns 400 - Bad Request). For the value 5, the controller takes the enum as Available|Deleted (4+1=5) and for the 7(4+3) it takes Modified|Deleted. I want to reject the values that are not in the enum class. How can I handle this?
