【发布时间】:2015-01-09 00:17:43
【问题描述】:
我花了大约 2 天的时间来设置我的 Odata Web API 项目,这是一个简单的 Asp.net mvc4 项目之前的项目。
但我仍然无法成功操作 CRUD 操作。 它是这样说的:
<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>
这意味着它到达控制器但没有找到动作或我的路由设置有问题。
我的 WebApiConfig 中有以下内容:
config.Routes.MapODataRoute("OData","odata",GetEdmModel());
我的 getEdmModel 方法:
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Product");
builder.EntitySet<OfferedProduct>("OfferedProduct");
IEdmModel model = builder.GetEdmModel();
return model;
}
我的控制器是这样的:
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
现在当我在浏览器中写这个时:
http://localhost:53208/odata/Product
它说我上面显示的错误..
请指导我哪里出了问题?
【问题讨论】:
标签: c# web-services rest asp.net-mvc-4 odata