asp.net mvc3 多个字段,怎么排序啊
,这有四个字段,要分别实现排序,
<div class="orderType">
<ul>
<a href="#"><li class="current" id="defaultSort">默认排序</li></a>
<a href="#"><li id="salerCredit">卖家信用</li></a>
<a class="current" href="#"><li id="priceSort">价格</li></a>
<a href="#"><li id="dateSort">最新发布</li></a>
</ul>
</div>
public static IQueryable<T> DataSorting<T>(IQueryable<T> source, string orderColumn, string sortDirection)
{
string sortingDir = string.Empty;
if (sortDirection.ToUpper().Trim() == "ASC")
sortingDir = "OrderBy";
else if (sortDirection.ToUpper().Trim() == "DESC")
sortingDir = "OrderByDescending";
ParameterExpression param = Expression.Parameter(typeof(T), orderColumn);
PropertyInfo pi = typeof(T).GetProperty(orderColumn);
Type[] types = new Type[2];
types[0] = typeof(T);
types[1] = pi.PropertyType;
Expression expr = Expression.Call(typeof(Queryable), sortingDir, types, source.Expression, Expression.Lambda(Expression.Property(param, orderColumn), param));
IQueryable<T> query = source.AsQueryable().Provider.CreateQuery<T>(expr);
return query;
}
var q = from a in tab1;
q=DataSorting<model>(q,"id","DESC");