0
I have a user registration where I use remote validation in the date Annotation to check if the user being registered already exists, my problem is in editing, as I am changing and using the same object the system thinks I am registering a new user and informs that I can not register because the informed record already exists.
How do I make sure that when I’m editing the record it doesn’t double check?
My model
[DisplayName("E-mail")]
[Required(ErrorMessage = "Favor informar o E-mail do usuário")]
[Remote("Unico", "Usuario", ErrorMessage = "Esse e-mail já existe no sistema")]
[RegularExpression(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}", ErrorMessage = "Favor informe um e-mail válido")]
public string email{ get; set; }
And here I have the remote validation function
public ActionResult Unico(string email)
{
try
{
int idUsuario = 123;//Usuário/ADM de teste
Models.user = bd.users.SingleOrDefault(s => s.email == email && s.idUsuario == idUsuario);
bool retorno = false;
if (c == null)
{
retorno = true;
}
return Json(retorno, JsonRequestBehavior.AllowGet);
}
catch
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
You can put snippets of your code from
Controller
who makes those transactions mentioned in the question?– Leonel Sanches da Silva
I edited including snippets of the code
– leedream
Two things: MVC has a tag called
[EmailAddress]
, that possibly validates even better the email than the regular expression used. The second thing is: where is the code that saves the record?– Leonel Sanches da Silva
I have to confirm more I think that the MVC4 does not have the validation [Emailadress], not object problems nor data recording. my point is that when editing the user it informs that this email already exists in the bank by using remote validation.
– leedream