Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在Web API调用中使用odata时发生空引用异常_Asp.net Mvc_Odata_Iqueryable_Asp.net Web Api - Fatal编程技术网

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

您“在调试器中没有可用的源代码”,但您可能有一个调用堆栈?