c# - How to Sort a List Generically -


i using html.grid of set of objects being pulled database (via linq sql). here grid code (i have changed data contrived). page strongly-typed people.

<%=html.grid<people>(model)     // display chose solution information.     .columns(column =>         {             column.for(person => person.name);             column.for(person => person.address.city);         }     ) %> 

within database, have people table , address table linked foreign key. (again, contrived - trying describe problem.)

i want allow user generically sort columns. previous developer had hard-coded in sorting within controller, so...

// // get: results/grid public actionresult grid(int id, gridsortoptions sort) {     if (sort == null)     {         sort = new gridsortoptions();     }      solution solution = repository.getsolution(id);     list<people> people = solution.people.tolist();     if (!string.isnullorempty(sort.column))     {         people = solution.people.tolist().orderby(sort.column, sort.direction).tolist();     }      return partialview("grid", people); } 

this works great when object sorting people (if click on person.name column sort ascending or descending). however, when want sort address column, exception because people not contain city...address does.

my question is...is there way sort generically without knowing type ahead of time? thanks.

how javascript table sorter? of course won't work if list big enough require paging.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -