title: How can I do sort an HTML table by header on web application mvc 4?
body: <p>I need help to sort the Id column. I researched how to sort the tables by the header, but could not find how to order tables in mvc, please help me to sort this table by header. I just need to sort the column ID</p>
  
  <p>All variables are in Models,
    this is my code on Controller:</p>
  
  <pre><code>        List&lt;PedidosPostosModel&gt; lista = new List&lt;PedidosPostosModel&gt;();
  
          PedidosPostosModel p1 = new PedidosPostosModel();
          p1.ID = 123;
          p1.DataPedido = DateTime.Now;
          p1.DataResposta = new DateTime(2015, 01, 15);
          p1.DataRecolha = new DateTime(2015, 01, 16);
          p1.Estado = "Executado";
          p1.Tipo = "Recolha";
          p1.Motorista = "13";
          lista.Add(p1);
  
          PedidosPostosModel p2 = new PedidosPostosModel();
          p2.ID = 13;
          p2.DataPedido = DateTime.Now;
          p2.DataResposta = new DateTime(2015, 01, 15);
          p2.DataRecolha = new DateTime(2015, 01, 16);
          p2.Estado = "Aceite";
          p2.Tipo = "Espera";
          p2.Motorista = "2";
          lista.Add(p2);
  
          PedidosPostosModel p3 = new PedidosPostosModel();
          p3.ID = 1;
          p3.DataPedido = DateTime.Now;
          p3.DataResposta = new DateTime(2015, 01, 15);
          p3.DataRecolha = new DateTime(2015, 01, 16);
          p3.Estado = "Anulado";
          p3.Tipo = "Material";
          p3.Motorista = "4";
          lista.Add(p3);
  
          PedidosPostosModel p4 = new PedidosPostosModel();
          p4.ID = 3;
          p4.DataPedido = DateTime.Now;
          p4.DataResposta = new DateTime(2015, 01, 15);
          p4.DataRecolha = new DateTime(2015, 01, 16);
          p4.Estado = "Executado";
          p4.Tipo = "Material";
          p4.Motorista = "8";
          lista.Add(p4);
  
          PedidosPostosModel p5 = new PedidosPostosModel();
          p5.ID = 123;
          p5.DataPedido = DateTime.Now;
          p5.DataResposta = new DateTime(2015, 01, 15);
          p5.DataRecolha = new DateTime(2015, 01, 16);
          p5.Estado = "Aceite";
          p5.Tipo = "Recolha";
          p5.Motorista = "9";
          lista.Add(p5);
  
          return View(lista);
  </code></pre>
  
  <p>This is my table in Views:      </p>
  
  <pre><code>d="myTable" class="table table-striped table-bordered" cellspacing="0"&gt;
                &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.ID)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.DataPedido)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.DataResposta)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.DataRecolha)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.Estado)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.Tipo)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.Motorista)
                          &lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  @foreach (var item in Model)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;
                              @item.ID
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.DataPedido
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.DataResposta
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.DataRecolha
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.Estado
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.Tipo
                          &lt;/td&gt;
                          &lt;td&gt;
                              @item.Motorista
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  }
              &lt;/table&gt; 
  </code></pre>