Lamba sorting for results I have the List method that takes sorting parameter to sort results.  The sorting parameter value is the same as the column name.

public ActionResult List(string sorting = "Name", string sortingMethod = "ASC")
{
    var productList = productRepository.Get();

    if(!String.IsNullOrEmpty(Sorting){
        if(String.IsNullOrEmpty(SortingMethod) ||SortingMethod == "ASC"){
            switch(sorting){
                case "Name" :
                    productList = productList.OrderBy(x =&gt; x.Name); break;
                case "Price" :
                    productList = productList.OrderBy(x =&gt; x.Price); break;
                case "Category" :
                    productList = productList.OrderBy(x =&gt; x.Price); break;
                //...
            }
        }else{
            switch(sorting){
                case "Name" :
                    productList = productList.OrderByDescending(x =&gt; x.Name); break;
                case "Price" :
                    productList = productList.OrderByDescending(x =&gt; x.Price); break;
                case "Category" :
                    productList = productList.OrderByDescending(x =&gt; x.Price); break;
                //...
            }
        }
    }

    return View(productList.ToList());
}


But I believe there is a better way to make code shorter.

public ActionResult List(string sorting = "Name", string sortingMethod = "ASC")
{
    var productList = productRepository.Get();

    if(!String.IsNullOrEmpty(Sorting){
        if(String.IsNullOrEmpty(SortingMethod) ||SortingMethod == "ASC"){
            productList = productList.OrderBy();  // &lt;== ???
        }else{
            productList = productList.OrderByDescending(); // &lt;== ???
        }
    }

    return View(productList.ToList());
}
What about seperating your sorting from your criteria?  I'm like you, I'm sure there is another way so am interested to see other opinions. I'm not exactly sure if this would scale for multiple orderBys either but I think it might (NOTE:  this code is untested and some types are not defined)

Something along the lines of:

public ActionResult List(string sorting = "Name", string sortingMethod = "ASC")
{
   var sortDirection = GetSortDirection(sortingMethod);
   var criteria = GetSortCriteria(sorting);

   var products = GetProductsOrderBy(criteria, sortDirection);

   return View(products.ToList());
}

// I'm not actually sure of the return type here.  Will attempt to test when I
// get in front of my development pc
Func&lt;Product, object&gt; GetSortCriteria(string sortOn) 
{
   switch(sortOn) 
   {
      case "Price":
      case "Category":
         return x =&gt; x.Price;
      default:
         return x.Name;
   }
}

IEnumerable&lt;ProductList&gt; GetProductsOrderBy(Action sortOn, SortDirection sortDirection)
{
    var productList = productRepository.Get();

    return sortDirection == SortDirection.Ascending ?
           productList.OrderBy(sortOn) :
           productList.OrderByDescending(sortOn);
}

SortDirection GetSortDirection(string sortBy) 
{
   return sortBy == "ASC" ? SortDirection.Ascending : SortDirection.Descending;
}