title: The model item passed into the ViewDataDictionary is of type X[] but this ViewDataDictionary instance requires a model item of type X
body: <p>Error:</p>
  
  <blockquote>
    <p>InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Test.Models.Ticket[]', but this ViewDataDictionary instance requires a model item of type 'Test.Models.Ticket'.</p>
  </blockquote>
  
  <p>Hello,<br>
  After staring at an error for a few days and doing some research, I've determined that I don't know enough about MVC to solve this problem. I understand enough to know that my controller is trying to pass an array to the view, but that the view is not looking for an array(?). Below is the code:</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>//this is supposed to take the last five "tickets" created from a database
  [Route("Ticket")]
  public IActionResult Index(int page = 0)
  {
      var model = _db.Tickets.OrderByDescending(x =&gt; x.Time).Take(5).ToArray();
      return View(model);
  }
  </code></pre>
  
  <p><strong>View:</strong> (file is titled "Index.cshtml" under the "Ticket" folder within the "Views" folder)</p>
  
  <pre><code>@model IEnumerable&lt;Test.Models.Ticket&gt;
  @{
      Layout = "_Layout";
  }
  
  &lt;p&gt;Below is supposed to display the latest 5 "tickets" from a database.&lt;/p&gt;
  
  &lt;div class="ticket-create"&gt;
      @foreach (var ticket in Model)
      {
          @Html.Partial("_Ticket", ticket)
      }
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Partial View "_Ticket":</strong></p>
  
  <pre><code>@model Test.Models.Ticket
  
  &lt;article class="ticket-create"&gt;
      &lt;h1&gt;@Html.ActionLink(Model.Type, "Create", "Ticket", new { year = Model.Time.Year, month = Model.Time.Month, day = Model.Time.Day, time = Model.Time.TimeOfDay, key = Model.Key })&lt;/h1&gt;
      &lt;div class="type"&gt;
          Created on &lt;span&gt;@Model.Time&lt;/span&gt; by &lt;span&gt;@Model.Name&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="desc"&gt;
          @Model.Desc
      &lt;/div&gt;
      &lt;div class="clearance"&gt;
          @Model.Clearance
      &lt;/div&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p><strong>Model "Ticket":</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Text.RegularExpressions;
  using System.Threading.Tasks;
  
  namespace Test.Models
  {
      public class Ticket
      {
          public long Id { get; set; }
  
          private string _key;
  
          public string Key
          {
              get
              {
                  if(_key == null)
                  {
                      _key = Regex.Replace(Name.ToLower(), "[^a-z0-9]", "-");
                  }
                  return _key;
              }
              set { _key = value; }
          }
  
          [Required]
          [DataType(DataType.Text)]
          public string Type { get; set; }
  
          [Required]
          [DataType(DataType.Text)]
          public string Name { get; set; }
  
          [StringLength(300, MinimumLength = 5, ErrorMessage = "The description must be between 5 and 300 characters long.")]
          [DataType(DataType.MultilineText)]
          public string Desc { get; set; }
  
          [DataType(DataType.DateTime)]
          public DateTime Time { get; set; }
  
          [Required]
          [DataType(DataType.Text)]
          public string Clearance { get; set; }
  
          [DataType(DataType.Text)]
          public string Author { get; set; }
      }
  }
  </code></pre>
  
  <p>_Layout.cshtml declares the following model: "@model Test.Models.Ticket"</p>
  
  <p>I read through a wonderful post located <a href="https://stackoverflow.com/questions/40373595/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-requ">here</a>, but while I think that helped me an awful lot in many aspects of my understanding of what's happening, I am still finding the error difficult to resolve.</p>