Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 按货币排序mvc3_Asp.net_Asp.net Mvc 3_Sorting - Fatal编程技术网

Asp.net 按货币排序mvc3

Asp.net 按货币排序mvc3,asp.net,asp.net-mvc-3,sorting,Asp.net,Asp.net Mvc 3,Sorting,我的班主任 public IQueryable<Products> SortProducts(int? GetPage, int? cat, string Sorter) { switch (Sorter) { case "date": return SortOrderByPage(GetPage, cat).OrderBy(p => p.Da

我的班主任

public IQueryable<Products> SortProducts(int? GetPage, int? cat, string Sorter)
        {
            switch (Sorter)
            {
                case "date":
                    return SortOrderByPage(GetPage, cat).OrderBy(p => p.Date);
                case "price":
                    return SortOrderByPage(GetPage, cat).OrderBy(p => p.Price);
                default:
                    return SortOrderByPage(GetPage, cat).OrderBy(p => p.Id);
            }
        }

这是什么??请帮助我

在比较字符串时,您看到的结果是预期的

任何以“1”开头的词都应该放在以“2”开头的词之前,就像“苹果”应该放在“香蕉”之前一样

由于您评论说您的价格存储为
string
s,因此您应该在排序之前将其解析为int。(或者更好:将其存储为int!)


“价格”可能是一个字符串吗?在这种情况下,将其解析为int.yes all price is string(但仅字段中的数字)表达式LINQ to Entities不识别方法“Int32 parse(System.string)”,。。。他,;他不知道上帝!(那么我建议您将系统更改为将价格存储为
int
s。毕竟,这是正确的方法。是的,我将DB、字符串编辑为int(表示价格)。case“price”:return SortOrderByPage(GetPage,cat)。OrderBy(p=>p.price);正确,谢谢!
price1: 104566
price2: 123566
price3: 124566
case "price":
    return SortOrderByPage(GetPage, cat).OrderBy(p => int.Parse(p.Price));