2013-07-09 71 views
2
public class XYZController : Controller 
    {    

     public ActionResult Index(ODataQueryOptions<Security> options = null) 
     { 
      var xyzs= GetXYZs().AsQueryable(); 
      var results = options == null ? xyzs: options.ApplyTo(xyzs); 
      return View(xyzs); 
     } 
    } 

这会导致“没有为此对象定义无参数构造函数”错误。不能将ODataQueryOptions与(常规 - 不是webapi)控制器派生类一起使用?

我基本上想要将符合odata的参数传递给常规控制器。

难道这不行吗?

回答

2

我暂时(直到常规控制器可以使用ODataQueryOptions)通过使用Linq2Rest的解决了这个(的NuGet:安装包Linq2Rest)

这个非常强大的图书馆让我完成我所用的一行找代码:

using Linq2Rest; 

public ActionResult Index() 
     { 
      var filteredSource = GetXYZs().AsQueryable().Filter(Request.Params); 

      return View(filteredSource); 
     } 

现在,你可以打这个控制器的索引操作是这样的: xyz.com?$filter=something eq 'foo' and another gt 3&$orderby another

0

ODataQueryOptions<T>现在仅支持Web API。这就是说,这是一个有趣的场景。我在codeplex上打开了这个issue来跟踪它。

+0

谢谢 - 我不知道是否有一种方法手动实例从该ODataQueryOptions请求上下文或传入过滤器,排序,组,计数等字符串patameters然后以某种方式用于手动初始化ODataQueryOptions上下文... – t316

相关问题