One of my actions takes args: String filter, String orderBy, String skip, String top
Yes, these map to OData system query options. Our database doesn't expose IQueryable<T>, so we parse the values ourselves, and pass the results to our stored procedures, and do our own filtering, ordering, skip and top. This works nicely
in WCF Web API.
Now, query string filter=N will be automatically mapped by MVC to action argument 'filter', but what I want is to map
$filter=N to 'filter'. Obviously C# doesn't allow an arg to be called "$filter".
Can you control this kind of mapping/binding in MVC?
awebb
Member
204 Points
91 Posts
Controlling the mapping of query string names to action argument names
Feb 27, 2012 04:06 PM|LINK
One of my actions takes args: String filter, String orderBy, String skip, String top
Yes, these map to OData system query options. Our database doesn't expose IQueryable<T>, so we parse the values ourselves, and pass the results to our stored procedures, and do our own filtering, ordering, skip and top. This works nicely in WCF Web API.
Now, query string filter=N will be automatically mapped by MVC to action argument 'filter', but what I want is to map $filter=N to 'filter'. Obviously C# doesn't allow an arg to be called "$filter".
Can you control this kind of mapping/binding in MVC?
SiggiGG
Member
265 Points
105 Posts
Re: Controlling the mapping of query string names to action argument names
Feb 27, 2012 04:40 PM|LINK
I believe you can use an attribute to control that, it would look something like this:
raghuramn
Member
248 Points
64 Posts
Microsoft
Re: Controlling the mapping of query string names to action argument names
Feb 27, 2012 09:48 PM|LINK
Did you try parsing the query parameters yourself. It might be simpler here.
awebb
Member
204 Points
91 Posts
Re: Controlling the mapping of query string names to action argument names
Feb 28, 2012 03:42 PM|LINK
@Siggi - thanks, this worked. As always, your knowledge impresses!
@raghuramn - I could pass the query parameters myself; you're right. Not as cool as Siggi's approach, but possibly more performant.