I have the following sittuation:
[Required(ErrorMessage = "Campo obrigatório!")]
[MaxLength(10, ErrorMessage = "Tamanho excedido!")]
[CustomDataAnnnotations.EhTelefoneViciado(ErrorMessage="Teste de validacao")]
public string NumeroTelefone1 { get; set; }
[CustomDataAnnnotations.ValidarDataAtual(ErrorMessage = "Data futura!")]
[Required(ErrorMessage = "Campo obrigatório!")]
[Display(Name = "Data Ocorrido *")]
public string DataOcorridos { get; set; }
This, generate the following HTML:
<span class="field-validation-error erro" data-valmsg-for="NumeroTelefone1" data-valmsg-replace="true" title="Teste de validacao"></span>
<span class="field-validation-error erro" data-valmsg-for="DataOcorridos" data-valmsg-replace="true">Data futura!</span>
Why on first scenario the message is in the TITLE of the SPAN and on the second IN the SPAN ? What i have to do, to generate like the second one?
I allready referenced the .js :
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/Scripts/jquery.validate.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.js")
@{Html.EnableClientValidation(true);}
@{Html.EnableUnobtrusiveJavaScript(true);}
Help me, please.
EDIT: Below are the CustomDataAnnotation:
public class CustomDataAnnnotations
{
public class ValidarDataAtualAttribute : ValidationAttribute
{
public ValidarDataAtualAttribute()
{
}
public override bool IsValid(object value)
{
//var dt = (DateTime)value;
var dt = DateTime.Parse(value.ToString());
if (dt <= DateTime.Now)
{
return true;
}
return false;
}
}
public class EhTelefoneViciadoAttribute : ValidationAttribute
{
public EhTelefoneViciadoAttribute()
{
}
public override bool IsValid(object value)
{
if (value == null) { return true; }
var numeroTelefone = value.ToString();
if (numeroTelefone.Length >= 8)
{
numeroTelefone = numeroTelefone.PadRight(8);
String[] telefonesViciados = { "00000000", "11111111", "22222222", "33333333", "44444444", "55555555", "66666666", "77777777", "88888888", "99999999", "21212121", "10101010", "12121212", "23232323", "65656565", "45454545", "56565656", "78787878", "89898989" };
if (telefonesViciados.Contains(numeroTelefone))
{
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
}
}
EDIT02: The HTML:
@Html.EditorFor(model => model.NumeroTelefone1, new { htmlAttributes = new { @class = "border-corner", @onkeydown = "return ValidateNumber(event);" } })
@Html.ValidationMessageFor(model => model.NumeroTelefone1, "", new { @class = "erro" }
EDIT03: The validation error ( The label "TESTE" has to be on the side of the red cross)