My controller has an [HttpGet] index() action that displays a form with several inputs that are not bound to my database. For example there is a drop-down containing all the years from 1960 to 2020. When a user selects one, the form is posted and the [HttpPost] action method finds every item in the database from that year. Works great!
I would like a user to be able to sort the results by item name. I would also eventually like to do pagination.
1. Is there a Javascript/CSS library that will do all this so I can just plug it in?
2. If not, I have attempted to code it. However I can't get the data to persist when I do something like this:
<a asp-action="Index" asp-route-sortorder="@ViewBag.NameSortParm">Sort by Airline / Bag Name</a>
in order to trigger this
switch (sortorder) { case "airline_desc": baglist = baglist.OrderByDescending(s => s.Airline).ToList(); break; case "year": baglist = baglist.OrderBy(s => s.Year).ToList(); break; case "year_desc": baglist = baglist.OrderByDescending(s => s.Year).ToList(); break; default: baglist = baglist.OrderBy(s => s.Airline).ToList(); break; }
which calls the Index() get method, meaning I've lost the filtered data from the model. It no longer has any idea that the data from the dropdown was say, 2005. I'm guessing that the original form shouldn't post and should instead use a querystring. is that a better way to go? Even so, it still doesn't help me retain only the 2005 data when sorting.
I suppose I could cache the results (now that I know how to do so) but it seems like there's a better, clearer way to do so.