无法获得动态OrderBy以在我的一般列表上工作 [英] Cannot get the dynamic OrderBy to work on my generic list

查看:115
本文介绍了无法获得动态OrderBy以在我的一般列表上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得动态的OrderBy来处理我的常规列表;

I cannot get the dynamic OrderBy to work on my generic list;

var list = CacheObjects.CompetencyAssessments
                       .Select(x => new CompetencyAssessmentLineViewModel(x))
                       .ToList();

var sortInfo = string.Format("{0} {1}", request.SortingName, request.SortingOrder);

var displayList = list.AsQueryable()
                      .OrderBy(sortInfo)
                      .Skip(startIndex)
                      .Take(pageLength);

我为OrderBy的动态功能使用了一个字符串. 但是代码无法编译;

I am using a string for the dynamic functionality of OrderBy. But the code does not compile;

错误1无法从用法中推断出方法'System.Linq.Queryable.OrderBy(System.Linq.IQueryable,System.Linq.Expressions.Expression>)'的类型参数.尝试显式指定类型参数.

Error 1 The type arguments for method 'System.Linq.Queryable.OrderBy(System.Linq.IQueryable, System.Linq.Expressions.Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

我在做什么错了?

方法的签名是:

public JsonResult GridData(JqGridRequest request)

JqGridRequest来自NuGet包Lib.Web.Mvc.所以:

and JqGridRequest is from the NuGet package Lib.Web.Mvc. So:

  • request.SortingName是带有字段名称的字符串,并且
  • request.SortingOrder是排序顺序
  • request.SortingName is a string with the name of the field, and
  • request.SortingOrder is the sort order

请参阅: http://tpeczek.com/2011/03/jqgrid-and-aspnet-mvc-strongly-typed.html

推荐答案

问题是动态库在我的项目中被引用了两次.至少我知道如果再次发生这种情况该怎么办.

The problem was that the Dynamic library was referenced twice in my project. At least I know what to look out for if something like this happens again.

这篇关于无法获得动态OrderBy以在我的一般列表上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆