How can I avoid 406 when getting OData.PageResult <T>?
I have an ODataController returning a PageResult page.
Api example:
public PageResult<Customer> Get(ODataQueryOptions options) {
// cut some stuff out...
PageResult<Customer> result = new PageResult<Customer>(
searchResults as IEnumerable<Customer>,
Request.GetNextPageLink(),
Request.GetInlineCount());
return result;
When I debug this, it seems that everything is in order, and to correctly return to the correct construction of the PageResult class. On the web page ..
Web example
using (var client = new HttpClient()) {
client.BaseAddress = new Uri(testURL);
string searchUrl = "api/customer?$top=1&$skip=0";
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata=verbose"));
HttpResponseMessage response = client.GetAsync(searchUrl).Result;
The response is StatusCode 406, with a reason phrase indicating that the content is inappropriate. It also does this if I define a new MediaTypeWithQualityHeaderValue ("application / json").
What do I need to change so that I successfully use this Api in the controller before passing it to the view?
+5
1 answer