按降序对列进行排序

按降序对列进行排序

本文介绍了如何按降序对列进行排序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按降序对列进行排序。



HomeController.cs

 [ HttpPost] 
private testContext db = new testContext();
public 列表< Table1> thistable = new List< Table1>();
public ActionResult Index( int Idt, string col01, string col02, string col03, string submitfn, int ?page)
{
thistable = db.Data1.ToList();
if (submitfn == SortIdt
{
var sortthistable = 来自 s db.Data1 select s;
sortthistable = sortthistable.OrderByDescending(s = > s.Idt);
thistable = sortthistable;
}
int pageSize = 5 ;
int pageNumber =(page ?? 1 );
return 查看(thistable.ToPagedList(pageNumber,pageSize));
}



Index.cshtml

 <   td     align   =  center >  @ Html.ActionLink(Idt,Index,new {submitfn =SortIdt})<   / td  >  



错误代码:

无法隐式转换类型'System.Linq.IQueryable< FilteringPagingSorting.Models.Table1>'到'System.Collections.Generic.List< FilteringPagingSorting.Models.Table1>'。存在显式转换(您是否错过了演员表?)
解决方案

I am trying to sort a column by descending order.

HomeController.cs

[HttpPost]
private testContext db = new testContext();
public List<Table1> thistable = new List<Table1>();
public ActionResult Index(int Idt, string col01, string col02, string col03, string submitfn, int? page)
{
    thistable = db.Data1.ToList();
    if (submitfn == "SortIdt")
    {
        var sortthistable = from s in db.Data1 select s;
        sortthistable = sortthistable.OrderByDescending(s => s.Idt);
        thistable = sortthistable;
    }
    int pageSize = 5;
    int pageNumber = (page ?? 1);
    return View(thistable.ToPagedList(pageNumber, pageSize));
}


Index.cshtml

<td align="center">@Html.ActionLink("Idt", "Index", new { submitfn = "SortIdt" })</td>


Error code:

Cannot implicitly convert type 'System.Linq.IQueryable<FilteringPagingSorting.Models.Table1>' to 'System.Collections.Generic.List<FilteringPagingSorting.Models.Table1>'. An explicit conversion exists (are you missing a cast?)
解决方案


这篇关于如何按降序对列进行排序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 11:44