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
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 .
Since you're using ASP.NET, you can also just use regular parameter binding .
For example, an ODataController
action method with the following prototype:
[EnableQuery]
public IQueryable<MyEntity> Get(string testParam = "")
will service a request at the following URL:
http://your.machine/api/odata/myentity?$count=true&$top=10&$skip=0&testParam=true
The OData parameters $count
, $top
, and $skip
will all be honored, and your custom testParam
will have the string "true"
assigned within the Get
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.