title: How to show only the last record in a view ASP MVC
body: <p>I am developping a ASP MVC project using Stored Procedures (Without Entity Framework).</p>
  
  <p>After setting data in a formulaire, I want to show only the last record and not getting all the data from my database.</p>
  
  <p>I know that I can write another method that select only the last record but I wonder if there is a solution to retrieve that from the view.</p>
  
  <p>This is what I ve tried :</p>
  
  <pre><code>  @for (var i = 0; i &lt; 1; i++) { 
          @foreach (var item in Model)
          {
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.FirstName)
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.FirstName)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.LastName)
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.LastName)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Address)
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Address)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Email)
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Email)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Phone)
              &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Phone)
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      @Html.DisplayNameFor(model =&gt; model.Date)
                  &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Date.Date)
                  &lt;/td&gt;
               &lt;/tr&gt;
               &lt;tr&gt;
                     &lt;th&gt;
                         @Html.DisplayNameFor(model =&gt; model.Time)
                     &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Time)
                  &lt;/td&gt;
                 &lt;/tr&gt;
                 &lt;tr&gt;
                     &lt;th&gt;
                         @Html.DisplayNameFor(model =&gt; model.Nbre_P)
                     &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Nbre_P)
                  &lt;/td&gt;
                 &lt;/tr&gt;
                 &lt;tr&gt;
                     &lt;th&gt;
                         @Html.DisplayNameFor(model =&gt; model.Items)
                     &lt;/th&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Items)
                  &lt;/td&gt;
                     &lt;/tr&gt;
  
          } } 
  </code></pre>
  
  <p>The Model Bestellung.cs :</p>
  
  <pre><code>public class Bestellung
  {
      public int BestellungId { get; set; }
  
      [Required]
      public DateTime Date { get; set; }
  
      [Required]
      public string Time { get; set; }
  
      public int Nbre_P { get; set; }
  
      public string Items { get; set; }
  
      [Display(Name = "Phone Number")]
      [DataType(DataType.PhoneNumber)]
      [Required(ErrorMessage = "Phone is required.")]
      [RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered phone format is not valid.")]
      public String Phone { get; set; }
  
      [Display(Name = "Email")]
      [EmailAddress(ErrorMessage = "Invalid Email Address")]
      [Required(ErrorMessage = "Email is required.")]
      [DataType(DataType.EmailAddress)]
      [StringLength(30)]
      public string Email { get; set; }
  
  
      [Display(Name = "First Name")]
      [Required(ErrorMessage = "First name is required.")]
      [StringLength(30)]
      public string FirstName { get; set; }
  
      [Display(Name = "Last Name")]
      [Required(ErrorMessage = "Last name is required.")]
      [StringLength(30)]
      public string LastName { get; set; }
  
      [Display(Name = "Address")]
      [Required(ErrorMessage = "Address is required.")]
      [StringLength(30)]
      public string Address { get; set; }
  }
  </code></pre>