Reputation: 11448
Is it possible to use oData queries with MVC 3 Actions if I return a Queryable? Like so:
public JsonResult GetComplaints()
{
var complaints = db.Complaints.AsQueryable();
return Json(complaints, JsonRequestBehavior.AllowGet);
}
or
public IQueryable<Complaint> GetComplaints()
{
return db.Complaints.AsQueryable();
}
If I call it like so:
$.ajax({
url: '@Url.Action("GetComplaints")?$filter=startswith(CompanyName, \'123\')',
type: 'GET',
success: function (data) {
console.log(data);
}
});
Upvotes: 2
Views: 1799
Reputation: 139748
Your second example action with the IQueryable<Complaint>
can function as an OData endpoint, but only if you are using Web API and the method is inside an ApiController
.
Regular MVC controllers don't support odata queries out of the box.
You can start learning about the OData support in Web.API from this article
OData can be installed as a Nuget package:
PM> Install-Package Microsoft.AspNet.WebApi.OData
Upvotes: 2