,这有四个字段,要分别实现排序,<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>
开始,我是想给他们分别,onclick事件,然后改变数据源的现实方式
var list from Model orderby 字段 select list
但是没有实现,各位帮帮忙asp.netmvc排序selectclass

解决方案 »

  1.   

    Model.OrderBy(x => x.xxx).ThenBy(x => x.yyy).ThenBy(x => x.zzz)
      

  2.   

    那你就把排序的字段和方式传过去啊,放在url里面也可以
      

  3.   


    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");
      

  4.   


    当个参数http://baidu.com?price=1&date=1