title: The model item passed into the ViewDataDictionary
body: <p>Hi I have problem in my code and it seems it has something to do with the instances but I declare already a instance in the controller and it seems it is not working.</p>
  
  <p>I got this error:</p>
  
  <blockquote>
    <p>InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[PEMCOLoan.DAL.Entities.spModels.spGetLedger]', but this ViewDataDictionary instance requires a model item of type 'PEMCOLoan.Web.Models.Ledger'.</p>
  </blockquote>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>[HttpPost]
      [ValidateAntiForgeryToken]
      public IActionResult getEmployeeLedger(spGetLedger ledger)
      {
          var firstDay = _Context.LoanPayments.Min(min =&gt; min.DateOfPayment);
          var lastDay = _Context.LoanPayments.Max(max =&gt; max.DateOfPayment);
  
          //Set Test data
  
          //Set Parameter
          var StartDate = new SqlParameter("StartDate", firstDay);
          var EndDate = new SqlParameter("EndDate", lastDay);
          var EmpID = new SqlParameter("EmployeeID", ledger.EmployeeID);
          var LoanTypeID = new SqlParameter("LoanType", ledger.LoanTypeID);
  
          Ledger newLedger = new Ledger();
  
          newLedger.enumledger = _Context.Set&lt;spGetLedger&gt;().FromSql("EXECUTE spGetLedger @EmployeeID, @LoanType, @StartDate, @EndDate", EmpID, LoanTypeID, StartDate, EndDate).AsNoTracking();
          //var empLedger = _Context.getLedger
          return View(newLedger.enumledger);
      }
  </code></pre>
  
  <p><strong>Views</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@model PEMCOLoan.Web.Models.Ledger
  
  @{ 
      ViewBag.Title = "Ledger";
  }
  
  &lt;h2&gt;View @Model.ledger.FullName's Ledger&lt;/h2&gt;
  &lt;h3&gt;Loan Name: @Model.ledger.LoanName&lt;/h3&gt;
  &lt;h3&gt;Total Loan Amount: @Model.ledger.TotalLoanAmount&lt;/h3&gt;
  
  @if (Model.enumledger.Any())
  {
      &lt;table class="table table-responsive"&gt;
          &lt;tr&gt;
              &lt;th&gt;Date Paid&lt;/th&gt;
              &lt;th&gt;Principal Amount&lt;/th&gt;
              &lt;th&gt;Interest&lt;/th&gt;
              &lt;th&gt;Total&lt;/th&gt;
          &lt;/tr&gt;
          @foreach(var item in Model.enumledger)
          {
              &lt;tr&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.PaymentDate)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.TotalLoanAmount)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Interest)&lt;/td&gt;
                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Total)&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/table&gt;
  }
  &lt;h3&gt;Balance: @Model.ledger.Balance&lt;/h3&gt;</code></pre>
  </div>
  </div>
  </p>