I have this simple piece of code
public ActionResult ListToGrid(string field, string direction)
{
_model.MyList = _repo.List();
}
To sort, I can do this :
_model.MyList = _employeeService.List().OrderBy(x => x.FirstName).ToList<Employee>();
But I’d like use “as field” the name receive (field) in argument and the direction received too.
Thanks,
You could use reflection, but that would be rather slow. The most efficient would be declare a delegate to use in the sort, and assign a function depending on the string:
For the direction I think it’s best to simply use separate codes: