Can you customize the error message of a property of type int?

0

I have the following model

public class UpdateViewModel
{
    [DataType(DataType.PhoneNumber, ErrorMessage = "El campo teléfono particular debe ser un número")]
    [Required(ErrorMessage = "El campo teléfono particular es obligatorio")]
    [Phone(ErrorMessage = "Ingresa un teléfono válido")]
    public int Telefono { get; set; }
}

Which I render in my view in the following way

@Html.EditorFor(m => m.Telefono, new { @class = "validate" })
@Html.LabelFor(m => m.Telefono)
@Html.ValidationMessageFor(m => m.Telefono, "", new { @class = "red-text" })

By default if you enter a string instead of a int in input you throw me an error message

  

The Phone field must be a number

But what I need to do is to customize that error message that throws me by the type of data and I can not find a way to do it.

    
asked by vcasas 25.06.2018 в 17:06
source

0 answers