I have a controller
[HttpGet]
[RoutePrefix(\"api/products/{productId}\")]
public HttpResponseMessage Products(int productId,TypeEnum ptype=TypeEnum.C
You have to do with string
and use TryParse()
to convert string to Enum
value.
public HttpResponseMessage Products(int productId,string ptype="Clothes")
{
TypeEnum category = TypeEnum.Clothes;
if(!Enum.TryParse(ptype, true, out category))
//throw bad request exception if you want. but it is fine to pass-through as default Cloathes value.
else
//continue processing
}
It may look naive but the benefit of this approach is to allow ptype
parameter to whatever string and to perform process without exception when ptype
fails to bind the value.