I'm trying to use Remote Validation
to check if the email is already registered, the problem is that whenever I report an email for example [email protected]
it does not return me that the email is already registered and it is registered, and if I I put [email protected]
ai returns the validation that the email is already registered, very strange it.
How do I solve this problem?
I'm trying like this.
User Class
[Serializable]
public class Usuario{
public virtual long id { get; set; }
[Required(ErrorMessage = "Informe o nome")]
[StringLength(50, MinimumLength = 5, ErrorMessage = "Campo nome deve ter de 5 a 50 caracteres")]
public virtual String nome {get;set;}
[Remote("isExistEmail", "Usuario", ErrorMessage = "Email já cadastrado!")]
[EmailBrasil(EmailRequerido=true)]
public virtual String email {get;set;}
[Required(ErrorMessage="Informe a senha")]
[SenhaBrasil(SenhaTamanhoMinimo = 8, SenhaTamanhoMaximo = 8, SenhaForteRequerida = false, CaracterEspecialRequerido = false)]
public virtual String senha {get;set;}
public virtual int status {get; set;} //1 ativo, 2 inativo, 0 aguardando
public Usuario() { }
}
Method that verifies that the email is registered in the user's controller.
public JsonResult isExistEmail(String email){
Boolean isExist = dao.isExist(email);
if (isExist){
return Json(true, JsonRequestBehavior.AllowGet);
}else{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
DAO that checks for email in database
//verifica se ja existe o email cadastrado
public Boolean isExist(String email){
ISession _session = getSession();
IList<Usuario> list = _session.CreateQuery("FROM Usuario u WHERE u.email = :email")
.SetParameter("email", email)
.SetMaxResults(1)
.List<Usuario>();
if (list.Count > 0){
return true;
}
return false;
}
HTML
<div class="form-group">
<label for="email" class="cols-sm-2 control-label">Email <img src="~/Imagens/required.png" height="6" width="6"></label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope" aria-hidden="true"></i></span>
@Html.TextBoxFor(model => Model.email, new { Class = "form-control", placeholder = "Informe o email", maxlength = 255 })
</div>
@Html.ValidationMessageFor(model => model.email)
</div>
</div>