Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebApi Default Args Binder
type CustomBinder() =
interface IModelBinder with
member this.BindModel(actionContext:HttpActionContext, bindingContext :ModelBindingContext) =
let qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query)
bindingContext.Model <-
if (qs.AllKeys |> Seq.exists(fun q -> q.ToLower() = bindingContext.ModelName.ToLower())) then
qs.[bindingContext.ModelName] |> Some
else
None
true
type CustomBinderProvider() =
inherit ModelBinderProvider()
override this.GetBinder(configuration: System.Web.Http.HttpConfiguration , modelType: System.Type) =
CustomBinder() :> IModelBinder
type TestController() =
inherit ApiController()
[<HttpGetAttribute>]
member this.Test([<ModelBinderAttribute(typeof<CustomBinderProvider>)>]?argument: string) =
let arg = defaultArg argument "Hello"
arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.