Asp.net mvc 在Web API调用中使用odata时发生空引用异常
我有以下产品类别:Asp.net mvc 在Web API调用中使用odata时发生空引用异常,asp.net-mvc,odata,iqueryable,asp.net-web-api,Asp.net Mvc,Odata,Iqueryable,Asp.net Web Api,我有以下产品类别: public class Product { public int Id { get; set; } public string Name { get; set; } } 以及以下Web API控制器类: public class ProductController : ApiController { public IQueryable<Product> Get() { var products = new Lis
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
以及以下Web API控制器类:
public class ProductController : ApiController
{
public IQueryable<Product> Get()
{
var products = new List<Product>
{
new Product {Id = 1, Name = "Beans"},
new Product {Id = 2, Name = "Sausages"},
new Product {Id = 3, Name = "Bread"}
};
return products.AsQueryable();
}
}
公共类ProductController:ApicController
{
公共IQueryable Get()
{
var产品=新列表
{
新产品{Id=1,Name=“Beans”},
新产品{Id=2,Name=“香肠”},
新产品{Id=3,Name=“Bread”}
};
退货产品。AsQueryable();
}
}
我在用小提琴向它提出请求。这些工作很好:
本地主机:49629/API/Product
localhost:49629/API/Product?$orderby=Name
但当我尝试使用过滤时,例如:
localhost:49629/API/Product?$filter=Id gt 2
出现空引用。调试器中没有可用的源代码,因此我不确定出了什么问题。有人能帮忙吗?对于Fiddler,您需要对请求进行编码: localhost:49629/API/Product?$filter=Id%20gt%202您“在调试器中没有可用的源代码”,但您可能有一个调用堆栈?