title: How to display Partial view Model errors when partial view is in the view?
body: <p>I am working on the Asp.net Core 2.0 project and have a <code>partial view</code> that is shown in the <code>index</code> view. This <code>partial view</code> have a Model with some validation errors.</p>
  
  <p>You can continue to see my Model,Partial view,controller and ... </p>
  
  <p><strong>LoginViewModel</strong></p>
  
  <pre><code>public class LoginViewModel
  {
      [Display(Name = "UserName")]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Please Enter UserName")]
      public string UserName { get; set; }
  
      [Display(Name = "Password")]
      [Required(AllowEmptyStrings = false, ErrorMessage = "Please Enter Password")]
      [DataType(DataType.Password)]
      public string Password { get; set; }
  
      [Display(Name = "Remember Me")]
      public bool RememberMe { get; set; }
  }
  </code></pre>
  
  <p>I have used <code>LoginViewModel</code> as <code>model</code> in <code>_loginpartialView</code>. also there are <code>asp-validation-for</code> to show validation error after each <code>input</code></p>
  
  <p><strong>_loginpartialView.cshtml</strong></p>
  
  <pre><code>@model partialView.Models.LoginViewModel
  
      &lt;div id="login"&gt;
          &lt;span class="header-lastnews"&gt;Login&lt;/span&gt;
          &lt;div class="hr"&gt;&lt;/div&gt;
  
          &lt;form asp-controller="Account" asp-action="Login" method="post"&gt;
  
  
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="UserName" class="col-sm-4 control-label"&gt;&lt;/label&gt;
                  &lt;div class="col-sm-8"&gt;
                      &lt;input asp-for="UserName" class="form-control" /&gt;
                      &lt;span asp-validation-for="UserName" class="text-danger"&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
  
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Password" class="col-sm-4 control-label"&gt;&lt;/label&gt;
                  &lt;div class="col-sm-8"&gt;
                      &lt;input asp-for="Password" class="form-control" /&gt;
                      &lt;span asp-validation-for="Password" class="text-danger"&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-sm-offset-2 col-sm-10"&gt;
                      &lt;div class="checkbox"&gt;
                          &lt;label asp-for="RememberMe"&gt;
                              &lt;input asp-for="RememberMe" /&gt;
                              @Html.DisplayNameFor(m =&gt; m.RememberMe)
                          &lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="row" style="width: 100%"&gt;
                  &lt;div class="form-group pull-left "&gt;
                      &lt;button type="submit" class="btn btn-success"&gt;Enter&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I have used <code>@Html.Partial</code> to render and show <code>partial view</code> in <code>index</code>
  Be careful that the <code>index</code> view is inside the <code>HomeController</code></p>
  
  <p><strong>Index.cshtml</strong></p>
  
  <pre><code>@{
       ViewData["Title"] = "Home Page";
  }
  
  @Html.Partial("_loginpartialView")
  </code></pre>
  
  <p>And at the end this is my <code>AccountController</code></p>
  
  <p><strong>AccountController</strong></p>
  
  <pre><code>    [HttpPost]
      public async Task&lt;IActionResult&gt; Login(LoginViewModel model)
      {
          if (ModelState.IsValid)
          {
              //Success Login
              //do Something
          }
          else
          {
              //if ModelState is invalid
              return PartialView("_loginpartialView", model);
          }
  
          //if UserName Or Password is incorrect
          return PartialView("_loginpartialView", model);
      }
  </code></pre>
  
  <p>But the problem is that when I click on the <code>submit</code> button without entering the inputs value, a new page opens and <code>partial view</code> and Model errors show on new page. 
  How can i show model errors in <code>partial view</code> in the same view not a new page?</p>