Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to sort Table1 in Descending Order I click on the column heading, Idt, and nothing happens.

HomeController.cs
C#
private testContext db = new testContext();
public List<Table1> thistable = new List<Table1>();
[HttpPost]
public ActionResult Index(int Idt)
{
    var sortthistable = from s in db.Data1 select s;
    sortthistable = sortthistable.OrderByDescending(s => s.Idt);
    thistable = sortthistable.ToList();
    return View(thistable);
 }

Index.cshtml
HTML
@Html.ActionLink("Idt", "Index")
Posted
Updated 8-Feb-15 11:24am
v3

1 solution

An idea can be-
1. Pass sorting info in querystring
2. Get the querystring as parameter in the action method
3. Sort the result accordingly and return the view.

Here is a very good article on this topic
Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application[^]

Hopefully, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900