Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 28, 2012 03:42 PM by awebb
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?
Feb 27, 2012 04:40 PM|LINK
I believe you can use an attribute to control that, it would look something like this:
public string Get([FromUri(Prefix = "$filter")]string filter)
Feb 27, 2012 09:48 PM|LINK
Did you try parsing the query parameters yourself. It might be simpler here.
string filter = Request.RequestUri.ParseQueryString()["$filter"];
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.