[英]ASP.NET Odata Web API CRUD Operations Not Working
I have spent a about 2 days setting up my Odata Web API project that was before a simple Asp.net mvc4 project. 我花了大约2天的时间来建立我的Odata Web API项目,该项目之前是一个简单的Asp.net mvc4项目。
But still I am not successful in operating even CRUD Operations. 但是我仍然无法成功执行CRUD操作。 It says this:
它说:
<m:message xml:lang="en-US">
No HTTP resource was found that matches the request URI 'http://localhost:53208/odata/Product'.
</m:message>
<m:innererror>
<m:message>
No action was found on the controller 'Product' that matches the request.
</m:message>
<m:type/>
<m:stacktrace/>
</m:innererror>
It means its reaching the Controller but not finding actions or there is some problem in my routing settings. 这意味着它到达了控制器,但没有找到动作,或者我的路由设置中存在一些问题。
I have following in my WebApiConfig: 我的WebApiConfig中有以下内容:
config.Routes.MapODataRoute("OData","odata",GetEdmModel());
My getEdmModel method: 我的getEdmModel方法:
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Product");
builder.EntitySet<OfferedProduct>("OfferedProduct");
IEdmModel model = builder.GetEdmModel();
return model;
}
My controller is like this: 我的控制器是这样的:
public class ProductController : EntitySetController<Product,int>
{
private OfferAssistantDbContext db = new OfferAssistantDbContext();
List<Product> Products = new OfferAssistantDbContext().Products.ToList();
// GET api/Product
[Queryable(PageSize = 10)]
public override IQueryable<Product> Get()
{
return Products.AsQueryable();
}
// GET api/Product/5
public Product GetProduct([FromODataUri] int id)
{
return Products[id];
}
/// and so on... but for this time lets work only on GET operation
Now when I write this in my browser: 现在,当我在浏览器中编写此代码时:
http://localhost:53208/odata/Product
it says the error I showed above.. 它说我上面显示的错误。
Please guide me where is the problem?
请指导我哪里出了问题?
我相信您的控制器需要从ODataController继承:
public class ProductController : ODataController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.