asp.net mvc 5 - Unable to apply sorting in MVC 5 -


i'm trying apply sorting in mvc 5 application. used code here apply sorting. unfortunately, not working , won't sort. missing something? datatypes used strings btw.

here code:

//controller public actionresult index(string sort)         {             viewbag.extsortparm = string.isnullorempty(sort) ? "ext_desc" : "";             viewbag.dtssortparm = sort == "dts" ? "dts_desc" : "dts";             var sales = s in db.sales1 select s;             switch (sort)             {                 case "ext_desc":                     sales = sales.orderbydescending(s => s.extserial);                     break;                                 case "dts":                     sales = sales.orderby(s => s.dts);                     break;                 case "dts_desc":                     sales = sales.orderbydescending(s => s.dts);                     break;                 default:                     sales = sales.orderby(s => s.extserial);                     break;             }             return view(db.sales1.tolist());                     } 

and view applied:

@html.actionlink("extserial", "index", new { sortorder = viewbag.extsortparm })  @html.actionlink("dts", "index", new { sortorder = viewbag.dtssortparm }) 

was there missed? dts date way in string type. here example value: 5/11/2015 5:29:56 am

db database & sales1 salesentity

you sorting collection following line returns original unsorted collection

return view(db.sales1.tolist()); 

you need return sorted collection view using

return view(sales.tolist());  

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -