title: How to get the last value from a model list without looping it in MVC?
body: <p>Here i need to get the last value from a model list in a view without looping it..Here is my controller code</p>
  
  <pre><code>public IList&lt;ProductDetailModel&gt; GetWPDetails()
              {
                  ProductDetailModel Viewmodel;
                  string funname = "GetCSpecialWPDetails";
                  List&lt;ProductDetailModel&gt; getWPDetails = new List&lt;ProductDetailModel&gt;();
                  getWPDetails = objrest.EcommerceWPDetails(funname);
                  List&lt;ProductDetailModel&gt; WPDetails = new List&lt;ProductDetailModel&gt;();
  
                  foreach (var item in getWPDetails)
                  {
                      Viewmodel = new ProductDetailModel();
                      Viewmodel.Productid = item.Productid;
                      Viewmodel.ProductName = item.ProductName;
                      Viewmodel.CategoryID = item.CategoryID;
                      Viewmodel.ProductRate = item.ProductRate;
                      Viewmodel.DiscountRate = item.DiscountRate;
                      Viewmodel.imageurl1 = item.imageurl1;
                      WPDetails.Add(Viewmodel);
                  }
                  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
                  SqlCommand cmd = new SqlCommand("SELECT ThemeColor,LayoutDesign FROM dbo.Cpecial_Partner_Design WHERE [PartnerID]='" + Partid + "'", con);
                  con.Open();
  
                  using (SqlDataReader myReader = cmd.ExecuteReader())
                  {
                      while (myReader.Read())
                      {
                          Viewmodel = new ProductDetailModel();
                          Viewmodel.ThemeColor = myReader["ThemeColor"].ToString();
                          Viewmodel.LayoutDesign = myReader["LayoutDesign"].ToString();
                          WPDetails.Add(Viewmodel);
                      }
  
                      myReader.Close();
                  }
                  con.Close();
                  return WPDetails;
  
              }
  </code></pre>
  
  <p>and here in view i am getting the values by looping the model and the total count is 47 but what i need is i need the 47th value alone that is the last value alone without any looping.</p>
  
  <p>View code</p>
  
  <pre><code>  @foreach (var item in Model)
         {
          @Html.EditorFor(modelItem =&gt; item.ThemeColor)
          @Html.EditorFor(modelItem =&gt; item.LayoutDesign)
         } 
  </code></pre>
  
  <p>Any suggestion?</p>