DataAnnotations [Required]

0

I have this ViewModel:

public class ActividadViewModel
{
    [Required(ErrorMessage = "Debe ingresar el tipo de actividad")]
    [Display(Name = "Actividad")]
    public string TipoActividad { get; set; }

    [Required(ErrorMessage = "Debe ingresar el estado")]
    [Display(Name = "Estado")]
    public string Confirma { get; set; }

    [Required(ErrorMessage = "Debe ingresar las actividades a realizar")]
    [DataType(DataType.Text)]
    [Display(Name = "Actividades a Realizar /Solicitudes /Información del Problema")]
    public string Activi { get; set; }

    [Required(ErrorMessage = "Debe ingresar la fecha inicial")]
    [DataType(DataType.DateTime)]
    [Display(Name = "Fecha Inicio")]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd hh:mm}", ApplyFormatInEditMode = true)]
    public DateTime VFechaInicio { get; set; }

    [Required(ErrorMessage = "Debe ingresar la fecha final")]
    [DataType(DataType.DateTime)]
    [Display(Name = "Fecha Fin")]
    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd hh:mm}", ApplyFormatInEditMode = true)]
    public DateTime VFechaTermino { get; set; }

    [Required(ErrorMessage = "Debe ingresar las actividades realizadas")]
    [DataType(DataType.Text)]
    [Display(Name = "Actividades Realizadas")]
    public string Activi_Realiza { get; set; }

    [Required(ErrorMessage = "Debe ingresar el contacto")]
    [Display(Name = "Contacto")]
    public string ContactoID { get; set; }
}

and when I create the form I do it with the html helpers for the required fields

asp-validation-for="Activi"

but at the moment of checking in the form, the error message does not appear, it simply passes me the invalid model.

Do you know what is needed?

    
asked by Sebastian Rico 23.02.2018 в 04:14
source

1 answer

0

Will it be necessary to add the jquery validation libraries? You can do it by including the following line of code in your views:

@section scripts
{
    @Scripts.Render("~/bundles/jqueryval")
}
    
answered by 23.02.2018 в 18:25