Search code examples
c#asp.netasp.net-mvcasp.net-web-apiodata

OData (create custom) query option


i need to create a custom query option and to be honest i have no idea where to start from. i don't know how they are created or what class handles them. On my project i have used markdown but i also need to enable ( in which case the text marked will be markdown ) or disable ( in this case i will have plain text ).

at this point my solution was to send a parameter to a function and tell it when to enable / disable

EX:

.../.../Namespace.MyFunction(markdown=1)

but i'm looking for a way to obtain this

.../.../...?$markdown=true

something like count query option.

Thank you


Solution

  • The dollar sign prefix should only be used with system query options. Think of $ as a reserved namespace. You can certainly use your own application-specific query options; just don't prefix them with $.

    To get the value of markdown from a request URI like http://host/path?markdown=true from within a controller method, use the GetQueryNameValuePairs extension method. See also How to access all querystring parameters as a dictionary.