title: Asp .NET Core 2.2 Razor Pages Layour and Partials
body: <p>I'm building an application in Asp .NET Core 2.2 using Razor Pages. My Login page is set and I want to be redirected to the main page.</p>
  
  <pre><code>   public IActionResult OnGet()
      {
          try
          {
              if (User.Identity.IsAuthenticated)
                  return RedirectToPage("/Account/Index");
          }
          catch (Exception ex)
          {
              Console.Write(ex);
          }
  
          return Page();
      }
  
  
  
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          try
          {
              // Verification.  
              if (ModelState.IsValid)
              {
                  // Dominio LDAP
                  string domain = "sd6.glb.corp.local";
  
                  // Verificação de autenticação na AD. 
                  var isValid = LdapAuthenticate(domain, login.Username, login.Password);
  
                  if (isValid)
                  {
                      var user = GetUser();
  
                      // Login.  
                      await SignInUser(user, login.RememberMe);
  
                      // Info.  
                      return RedirectToPage("/Account/Index");
                  }
                  else
                  {
                      // Setting.  
                      ModelState.AddModelError(string.Empty, "Username / Password Incorrecto(s).");
                  }
              }
          }
          catch (Exception ex)
          {
              Console.Write(ex);
          }
  
          return Page();
      }
  </code></pre>
  
  <p>Problem is when I am redirected to Account/Index page</p>
  
  <p>I get this exception</p>
  
  <blockquote>
    <p>InvalidOperationException: The model item passed into the
    ViewDataDictionary is of type
    'Abastecimento.Pages.Account.IndexModel', but this ViewDataDictionary
    instance requires a model item of type
    'Abastecimento.Pages.Shared.Pages_Shared__NavbarPartial'.</p>
  </blockquote>
  
  <p>Here is my layout</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;
      &lt;title&gt;@ViewData["Title"] - Abastecimento&lt;/title&gt;
  
      &lt;environment include="Development"&gt;
          &lt;link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /&gt;
          &lt;link rel="stylesheet" href="~/lib/adminlte/dist/css/adminlte.css" /&gt;        
      &lt;/environment&gt;
      &lt;environment exclude="Development"&gt;
          &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
                asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
                asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute"
                crossorigin="anonymous"
                integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"/&gt;
      &lt;/environment&gt;
      &lt;link rel="stylesheet" href="~/css/site.css" /&gt;
  &lt;/head&gt;
  &lt;body class="sidebar-mini"&gt;
  
      &lt;div class="wrapper"&gt;
          &lt;!-- Navbar --&gt;
          &lt;partial name="_NavbarPartial" /&gt;
          &lt;!-- /.navbar --&gt;
          &lt;partial name="_SidebarPartial" /&gt;
          &lt;!-- Main Sidebar Container --&gt;
          &lt;!-- Content Wrapper. Contains page content --&gt;
          &lt;div class="content-wrapper"&gt;
              &lt;!-- Content Header (Page header) --&gt;
              &lt;div class="content-header"&gt;
                  &lt;div class="container-fluid"&gt;
                      @*&lt;div class="row mb-2"&gt;
                          &lt;div class="col-sm-6"&gt;
                              &lt;h1 class="m-0 text-dark"&gt;Starter Page&lt;/h1&gt;
                          &lt;/div&gt;&lt;!-- /.col --&gt;
                          &lt;div class="col-sm-6"&gt;
                              &lt;ol class="breadcrumb float-sm-right"&gt;
                                  &lt;li class="breadcrumb-item"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
                                  &lt;li class="breadcrumb-item active"&gt;Starter Page&lt;/li&gt;
                              &lt;/ol&gt;
                          &lt;/div&gt;&lt;!-- /.col --&gt;
                      &lt;/div&gt;&lt;!-- /.row --&gt;*@
                  &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
              &lt;/div&gt;
              &lt;!-- /.content-header --&gt;
              &lt;!-- Main content --&gt;
              &lt;div class="content fade-in"&gt;
                  &lt;div class="container-fluid my-5 pb-4"&gt;
  
                      @RenderBody()
  
                  &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
              &lt;/div&gt;
              &lt;!-- /.content --&gt;
          &lt;/div&gt;
          &lt;!-- /.content-wrapper --&gt;
          &lt;!-- Main Footer --&gt;
          &lt;partial name="_FooterPartial" /&gt;   
      &lt;/div&gt;
  
  
      &lt;environment include="Development"&gt;
          &lt;script src="~/lib/jquery/dist/jquery.js"&gt;&lt;/script&gt;
          &lt;script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"&gt;&lt;/script&gt;
          &lt;script src="~/lib/adminlte/dist/js/adminlte.js"&gt;&lt;/script&gt;
      &lt;/environment&gt;
      &lt;environment exclude="Development"&gt;
          &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
                  asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                  asp-fallback-test="window.jQuery"
                  crossorigin="anonymous"
                  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="&gt;
          &lt;/script&gt;
          &lt;script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"
                  asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
                  asp-fallback-test="window.jQuery &amp;&amp; window.jQuery.fn &amp;&amp; window.jQuery.fn.modal"
                  crossorigin="anonymous"
                  integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o"&gt;
          &lt;/script&gt;
      &lt;/environment&gt;
  
      &lt;script src="~/js/site.js" asp-append-version="true"&gt;&lt;/script&gt;
  
      @RenderSection("Scripts", required: false)
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my navbar partial</p>
  
  <pre><code>@page
  
  &lt;!-- Navbar --&gt;
  &lt;nav class="main-header navbar navbar-expand navbar-dark bg-danger border-bottom custom-sidebar fixed-top"&gt;
      &lt;!-- Left navbar links --&gt;
      &lt;ul class="navbar-nav"&gt;
          &lt;li class="nav-item "&gt;
              &lt;a class="nav-link custom-nav-link custom-navbar-links" data-widget="pushmenu" href="#"&gt;&lt;i class="fas fa-bars"&gt;&lt;/i&gt;&lt;/a&gt;
          &lt;/li&gt;
          &lt;li class="nav-item d-none d-sm-inline-block"&gt;
  
              &lt;a href="/Account/Index" class="nav-link custom-navbar-links"&gt;
                  &lt;p&gt;
                      &lt;i class="fas fa-home"&gt;&lt;/i&gt;
                      Início
                  &lt;/p&gt;
              &lt;/a&gt;
  
          &lt;/li&gt;
          &lt;li class="nav-item d-none d-sm-inline-block"&gt;
  
              &lt;a href="/Account/Home/Suporte" class="nav-link custom-navbar-links"&gt;
                  &lt;p&gt;
                      &lt;i class="fas fa-question"&gt;&lt;/i&gt;
                      Suporte
                  &lt;/p&gt;
              &lt;/a&gt;
  
          &lt;/li&gt;
      &lt;/ul&gt;
  
      &lt;!-- Right navbar links --&gt;
      &lt;ul class="navbar-nav ml-auto"&gt;
  
          &lt;li class="nav-item"&gt;
              &lt;a class="nav-link custom-navbar-links" href="/Account/Logout"&gt;
                  &lt;i class="fas fa-sign-out-alt"&gt;&lt;/i&gt;
                  Terminar Sessão
              &lt;/a&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  &lt;!-- /.navbar --&gt;
  </code></pre>
  
  <p>this works correctly on asp net MVC 5 using partial views, but i can't figure out what's causing this error.</p>