title: How to validate if email attribute is unique in an ASP .NET CORE API?
body: <p>I was needing to make a post or put a validation on the server side to check if the email is unique.</p>
  
  <p>In the research I have always done the example was a traditional MVC application and never an api.</p>
  
  <p>In many cases I saw that the [Remote] <a href="https://docs.microsoft.com/pt-br/aspnet/core/mvc/models/validation?view=aspnetcore-2.2#remote-attribute" rel="nofollow noreferrer">https://docs.microsoft.com/pt-br/aspnet/core/mvc/models/validation?view=aspnetcore-2.2#remote-attribute</a> . I tried to implement according to the documentation, but debugging verified that the function in the controller is neither called.</p>
  
  <p>User.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  using Microsoft.AspNetCore.Mvc;
  
  namespace Base.Models
  {
      [Table("users")]
      public partial class User
      {
          ...
          [Required]
          [EmailAddress]
          [Remote(action: "VerifyEmail", controller: "UserController",ErrorMessage="Email already in use")]
          [Column("email", TypeName = "varchar(254)")]
          public string Email { get; set; }
          ...
      }
  }
  </code></pre>
  
  <p>UserController.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.EntityFrameworkCore;
  using Base.Models;
  
  namespace Base.Controllers
  {
      [Route("api/users")]
      [ApiController]
      public class UserController : Controller
      {
          ...
          [AcceptVerbs("Get")]
          public IActionResult VerifyEmail(string email)
          {
              //forcing it to go wrong
              return Json($"Email {email} is already in use.");
          }
          ...
      }
  }
  
  </code></pre>
  
  <p>Anyone have any idea how to implement this?</p>