title: PartialView with Index/Create pages?
body: <p>Just wondering if anyone can clear up the correct theory or method of having a partial view between my Index and Create pages. Essentially what I am trying to achieve is an Index page that lets me add new entries (Create).</p>
  <p>Standard .net core 5 project scaffolded from a DB table, the main issues seems to be that the Index uses and IEnumerable and the Create page uses just the Model. I have tried both ways Index to Create / Create to Index to implement a partial view, when working with two Model pages like Create and Edit the partial view implements easily as expected.</p>
  <p>There are many ways in asp.net older versions it seems but this works for like models</p>
  <p><code>@Html.Partial(&quot;_CreatePartial&quot;)</code></p>
  <p>Is a partial view what I am looking for? Or is there a better way to do things? Just hard to figure out what options I even have as far as googling stuff. I see a lot of asp.net examples don't have issues like this or don't include lists or models.</p>
  <p>I would think this is a somewhat basic and common request, just a pointer in the right direction and terms to research would be appreciated.</p>
  <p><strong>Edit</strong></p>
  <p>My Index.cshtml starts with
  <code>@model IEnumerable&lt;TNA.Models.Tna&gt;</code></p>
  <p>My Create/Edit/Delete starts with
  <code>@model TNA.Models.Tna</code></p>
  <p><strong>Error message is this</strong>
  <code>InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List`1[TNA.Models.Tna]', but this ViewDataDictionary instance requires a model item of type 'TNA.Models.Tna'.</code></p>
  <p>So I am trying to insert a PartialView from a model into a page that is based on an Enumerable list. Can't see any hints online, I have tried other deprecated methods that present other challenges revolving around the same thing.</p>
  <p>Index</p>
  <pre><code>
  @{
      ViewData[&quot;Title&quot;] = &quot;Index&quot;;
  }
  
  &lt;table class=&quot;table&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Date)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.EmployeeId)
              &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Date)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.EmployeeId)
              &lt;/td&gt;
          &lt;/tr&gt;
  }
      &lt;/tbody&gt;
  &lt;/table&gt;
  
  **@Html.Partial(&quot;_CreatePartial&quot;)**
  </code></pre>
  <p>Create</p>
  <pre><code>@model TNA_BWEL.Models.TnaBwel
  
  @{
      ViewData[&quot;Title&quot;] = &quot;Create&quot;;
  }
  
  &lt;h1&gt;Create&lt;/h1&gt;
  
  &lt;h4&gt;TnaBwel&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-4&quot;&gt;
          &lt;form asp-action=&quot;Create&quot;&gt;
              &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label asp-for=&quot;Date&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
                  &lt;input asp-for=&quot;Date&quot; type=&quot;date&quot; class=&quot;form-control&quot; /&gt;
                  &lt;span asp-validation-for=&quot;Date&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;a asp-action=&quot;Index&quot;&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync(&quot;_ValidationScriptsPartial&quot;);}
  }
  
  </code></pre>
  <p>Controller</p>
  <pre><code>namespace TNA.Controllers
  {
      public class TnasController : Controller
      {
          private readonly ApplicationDbContext _context;
  
          public TnasController(ApplicationDbContext context)
          {
              _context = context;
          }
  
          // GET: Tnas
          public async Task&lt;IActionResult&gt; Index()
          {
              return View(await _context.Tnas.ToListAsync());
          }
  
          public IActionResult Create()
          {
              return View();
          }
  
          [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Create([Bind(&quot;Id,Date&quot;)] Tna tna)
          {
              if (ModelState.IsValid)
              {
                  _context.Add(tna);
                  await _context.SaveChangesAsync();
                  return RedirectToAction(nameof(Index));
              }
              return View(tna);
          }
  
  </code></pre>
  <p>Partial views are near identical to standard views, not much to see since it is a scaffolded new project, never done this before in a .net project and was trying to get the unknowns out of the way.</p>