So I have a controller that accepts a string "sortBy"
My Controller:
public async Task<ViewResult> ActivityManagementTwo(DateFilterModel filters, int pageSize = 25, int page = 1, string sortBy = "")
{
// do stuff
Activities = activities.OrderBy(a=> a.GetType().GetProperty(sortBy)).Skip((page-1)*pageSize).Take(pageSize),
// do more stuff
}
I want to basically say
if(sortBy == "dateTimeOfCall") activities.orderBy(a=> a.dateTimeOfCall);
else if (sortyBy == "trackingNumber") activities.orderBy(a=>a.trackingNumber);
// so on and so forth-
but I don't want to make a seperate if statement for each property in activities. Is there a short way to orderby a property that matches a string?