Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Optional query parameters in webapi #95

Open
pavelm opened this issue Jan 25, 2015 · 1 comment
Open

Optional query parameters in webapi #95

pavelm opened this issue Jan 25, 2015 · 1 comment

Comments

@pavelm
Copy link

pavelm commented Jan 25, 2015

I was converting a C# webapi project to F# using the F# ASP.NET templates. Everything is working great except optional query parameters. I keep getting this error

{
    "message": "The request is invalid.",
    "messageDetail": "The parameters dictionary contains an invalid entry for parameter 'start' for method 'System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage] GetVendorFiles(Int32, System.Nullable`1[System.DateTime])' in 'Thor.WebApi.VendorFilesController'. The dictionary contains a value of type 'System.Reflection.Missing', but the parameter requires a value of type 'System.Nullable`1[System.DateTime]'."
}

F# function signature:

        [<HttpGet; Route("")>]
        member x.GetVendorFiles( [<Optional; DefaultParameterValue(100)>] count, [<Optional; DefaultParameterValue(null)>] start : Nullable<DateTime> ) =

C# function signature:

        [HttpGet]
        [Route("")]
        public async Task<HttpResponseMessage> GetVendorFiles(int count = 100,DateTime? start = null)

Does any one know of any work arounds?

@panesofglass
Copy link
Collaborator

For what it's worth, I rarely use the parameter bindings. I find request.GetQueryNameValuePairs() a more reliable mechanism, especially when you want optional parameters. F# doesn't seem to map well to the MVC conventions for parameter binding. I'm sure this is not the answer for which you hoped, but I've never been able to get parameter binding to work reliably. You ma want to raise this in https://github.com/Microsoft/visualfsharp/issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants