Best practice for passing enum params in Web API

The simplest answer is, “It doesn’t matter”.

If the parameter in your controller method is of the enumeration type

public IHttpActionResult Foo(RuleType ruleType)

In WebAPI, It Just Works – no matter if the client request URL specifies the parmeter value as ?ruleType=1 or ?ruleType=EmailAddress

If the client specifies a value that isn’t valid for the enumeration, an exception is thrown (The parameters dictionary contains a null entry for parameter 'ruleType' of non-nullable type 'RuleType' for method 'Foo' ... and the client gets a 400 Bad Request response.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)