问题
I'm getting an exception on my Web API controller end-point and I would really apricaite some help in solving this:
Here is the story:
My Web API project a controller exposes the following End-Point:

My Kendo UI Datagrid makes the following request:
http://localhost:63865/api/employees/GetAll?$callback=jQuery21109420544053427875_1410883352953&%24inlinecount=allpages&%24format=json&%24top=5
When validating the ODataQueryOptions sent in the request, I'm getting this exception:
Query option 'Format' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.

But I've actually enabled all query options
[EnableQuery(AllowedQueryOptions=AllowedQueryOptions.All)]
What I'm I doing wrong ?
回答1:
Finally manage to get to the bottom of this!
After creating the ODataValidationSettings object I needed to change the AllowedQueryOptions to AllowedQueryOptions.All. Be default all options are there except the Format and SkipToken.

Anyway, hope this may help anyone else facing the same issue.
回答2:
I had the same issue but I had to solve it a different way. My OData service controll was generated using Entity Framework (data first) and it turns out Microsoft's template doesn't support all the OData parameters. This puzzled me because I don't need the extra parameters anyway because I was just trying to define a datasource for use with a TreeView Kendo component. I finally found the Telerik blog post that went into detail about Using Kendo UI With MVC4, WebAPI, OData And EF which focussed on the 'inlinecount' param but for me the culprit was the 'format' param.
I'm pasting the summary from that page here in case the link goes bad.
Remove Inline Count Parameter
transport: {
read: {
url: "/api/Albums", // <-- Get data from here
dataType: "json" // <-- The default was "jsonp"
},
parameterMap: function (options, operation) {
var paramMap = kendo.data.transports.odata.parameterMap(options);
delete paramMap.$inlinecount; // <-- remove inlinecount parameter
delete paramMap.$format; // <-- remove format parameter
return paramMap;
}
}
来源:https://stackoverflow.com/questions/25874020/query-option-format-is-not-allowed-to-allow-it-set-the-allowedqueryoptions