title: Status Code: 415 Unsupported Media Type in MVC
body: <p>I seen this error for the first time in my practice.My project is .Net Core 2.1 MVC.The error is thrown when I try to login.There are nothning special.Simple AccountController and login form like ussual.
  The Error: Status Code: 415; Unsupported Media Type
  Controller:</p>
  <pre><code>[HttpPost]
      [AllowAnonymous]
      public async Task&lt;IActionResult&gt; Login([FromForm]LoginViewModel loginViewModel)
      {
          if (!ModelState.IsValid)
          {
              return View(loginViewModel);
          }
  
          IdentityUser user = null;
  
          if (loginViewModel.EmailOrUsername.Contains(&quot;@&quot;))
          {
              user = await _userManager.FindByEmailAsync(loginViewModel.EmailOrUsername);
          }
          else
          {
              user = await _userManager.FindByNameAsync(loginViewModel.EmailOrUsername);
          }
  
          if (user != null)
          {
              var result = await _signInManager.PasswordSignInAsync(user, loginViewModel.Password, false, false);
              if (result.Succeeded)
              {
                  return Redirect(loginViewModel.ReturnUrl ?? &quot;/&quot;);
              }
          }
  
          ModelState.AddModelError(&quot;&quot;, &quot;Invalid Username or Password&quot;);
          return View(loginViewModel);
      }
  </code></pre>
  <p>Form:</p>
  <pre><code>&lt;form asp-action=&quot;login&quot; asp-controller=&quot;account&quot; method=&quot;post&quot;&gt;
          &lt;input type=&quot;hidden&quot; asp-for=&quot;ReturnUrl&quot; /&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;label asp-for=&quot;EmailOrUsername&quot;&gt;&lt;/label&gt;
              &lt;input asp-for=&quot;EmailOrUsername&quot; class=&quot;form-control&quot; /&gt;
              &lt;span asp-validation-for=&quot;EmailOrUsername&quot;&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;label asp-for=&quot;Password&quot;&gt;&lt;/label&gt;
              &lt;input asp-for=&quot;Password&quot; class=&quot;form-control&quot; /&gt;
              &lt;span asp-validation-for=&quot;Password&quot;&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;button type=&quot;submit&quot; class=&quot;btn buy-now-btn&quot;&gt;Login&lt;/button&gt;
          &lt;a asp-action=&quot;register&quot; asp-route-returnUrl=&quot;@Model.ReturnUrl&quot; class=&quot;float-right&quot;&gt;Don't have an account? Register here!&lt;/a&gt;
      &lt;/form&gt;
  </code></pre>
  <p>And finaly Model:</p>
  <pre><code>public class LoginViewModel
  {
      [Required]
      [Display(Name = &quot;Email/Username&quot;)]
      public string EmailOrUsername { get; set; }
  
      [Required]
      [DataType(DataType.Password)]
      public string Password { get; set; }
  
      public string ReturnUrl { get; set; }
  }
  </code></pre>