title: Trying to use a ViewModel on a partial view
body: <p>So I'm editing the default ASP.NET MVC with authentication template, and I'm trying to create a ViewModel for <code>_PartialLogin.cshtml</code> in order to display a name instead of the user's e-mail. I searched a lot of things, but they were pretty outdated so I hope someone can help. I don't even know if creating a ViewModel is the best option.</p>
  
  <p>Here's the <code>LoginPartialViewModel</code>:</p>
  
  <pre><code>namespace AplicacaoRoles2.Models.SharedViewModels
  {
      public class PartialLoginViewModel
      {
          [Required]
          public string Nome { get; set; }
      }
  }
  </code></pre>
  
  <p><code>_LoginPartial.cshtml</code>:</p>
  
  <pre><code>@using Microsoft.AspNetCore.Identity
  @using AplicacaoRoles2.Models
  
  @model AplicacaoRoles2.Models.SharedViewModels.PartialLoginViewModel
  
  @inject SignInManager&lt;ApplicationUser&gt; SignInManager
  @inject UserManager&lt;ApplicationUser&gt; UserManager
  
  @if (SignInManager.IsSignedIn(User))
  {
      &lt;form asp-area="" asp-controller="Account" asp-action="Logout" method="post" id="logoutForm" class="navbar-right"&gt;
          &lt;ul class="nav navbar-nav navbar-right"&gt;
              &lt;li&gt;
                  &lt;a asp-area="" asp-controller="Manage" asp-action="Index" title="Manage"&gt;Hello @Html.DisplayFor(model =&gt; model.Nome) !&lt;/a&gt;
              &lt;/li&gt;
  </code></pre>
  
  <p>(...)
  <code>HomeController</code>:</p>
  
  <pre><code>public class HomeController : Controller
  {
      private readonly ApplicationDbContext _context;
  
      public HomeController(ApplicationDbContext context)
      {
          _context = context;
      }
  
      public async Task&lt;IActionResult&gt; Index()
      {
          PartialLoginViewModel model = new PartialLoginViewModel();
          var userName = User.Identity.Name;
          var applicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m =&gt; m.UserName == userName);
  
          model.Nome = applicationUser.Nome;
  
          return View(model);
      }
  </code></pre>
  
  <p>On <code>_Layout.cshtml</code> there's this portion useful:</p>
  
  <pre><code>@Html.Partial("_LoginPartial")
  </code></pre>
  
  <p>(the code is simplified to shorted this)</p>
  
  <p>So this is working fine while I'm on <code>Home/index</code> because it as no Model, but as soon as I enter a page with a model it shows an model error thing.</p>
  
  <p>I could replace:</p>
  
  <pre><code>@Html.Partial("_LoginPartial")
  </code></pre>
  
  <p>for</p>
  
  <pre><code>@Html.Partial("_LoginPartial", new AplicacaoRoles2.Models.SharedViewModels.PartialLoginViewModel())
  </code></pre>
  
  <p>But the problem is that I lose the information by creating a new instance...
  Thank you.</p>
  
  <p>**Some words like 'Nome' are not misspelled, they are in portuguese</p>