我正在尝试将字符串路由参数绑定到枚举类型,如下所示
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "ValidateKey/{keyType}/{key}")]HttpRequestMessage req, KeyType keyType, string key, TraceWriter log)
当我到达端点时,代码给了我以下异常。
异常绑定参数 'req' -> 从 'System.String' 到 'MyCommon.KeyType' 的无效转换。”
模型绑定器无法将字符串参数绑定到 Enum 类型。在 MVC 或 WebAPI 应用程序中,绑定到 Enum 可以正常工作,但 AzureFunction 似乎不支持绑定。无论如何要在 AzureFunction 中插入自定义 ModelBinder 以使其工作?