Check Username Exist or Not using JSON in MVC

In the model: 
  1. public class User  
  2. {  
  3.    
  4.    [Key]  
  5.    public int UserId { getset; }  


  6.    [System.Web.Mvc.Remote("DoesUsernameExist""Admin", HttpMethod = "POST", ErrorMessage = "Username name already exists.")]  
  7.    public string Username { getset; }  

  8. }  
In the controller:
  1. [HttpPost]    
  2. public JsonResult DoesUsernameExist(string Username)    
  3. {    
  4.    var db = new ApplicationDbContext();    
  5.    var data = db.Users.Where(e => e.Username.Equals(Username, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();    
  6.    return Json(data == null);    
  7. }  
DoesUsernameExist - Action Name
Admin - Controller Name

We can pass additional fields like this -
  1. [System.Web.Mvc.Remote("DoesUsernameExist""Admin", AdditionalFields = "UserId", HttpMethod ="POST", ErrorMessage = "Username name already exists.")]