I am using remote validation for checking if email already exist in database but it is not working, here is the code:
Model Property
[Remote("IsAlreadyUserExist", "User", HttpMethod = "POST", ErrorMessage = "Email Already Exists.")]
public string Email { get; set; }
Controller
[HttpPost]
public JsonResult IsAlreadyUserExist(string Email)
{
return Json(IsUserExist(Email));
}
public bool IsUserExist(string Email)
{
List<UserProfile> userlist = userRepo.GetUserList();
var UserEmailId = (from u in userlist
where u.Email.ToUpper() == Email.ToUpper()
select new { Email }).FirstOrDefault();
bool status;
if (UserEmailId != null)
{
//Already registered
status = false;
}
else
{
//Available to use
status = true;
}
return status;
}
I have added this js in my Create view at the bottom.
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
I also tried putting debugger in IsAlreadyUserExist
function but it is not hitting there.
Any idea what could be the problem?