Link to home
Start Free TrialLog in
Avatar of Steven
StevenFlag for United States of America

asked on

cannot convert from viewmodel to model when saving changes

Good morning,
im getting the error show in the picture bellow, I've seen other examples and it should work, am I doing something wrong?

User generated image
my model
 public class Usuario
    {
        public int Id { get; set; }
        
        [Required]
        [StringLength(80)]
        public string Nombres { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name ="Primer apellido")]
        public string PrimerApellido { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name = "Segundo apellido")]
        public string SegundoApellido { get; set; }

        [Required]
        [StringLength(30)]
        public string Cedula { get; set; }

        [Required]
        [Display(Name = "Fecha nacimiento ")]
        public DateTime FechaNacimiento { get; set; }

        [Required]
        [StringLength(5)]
        public string Rh { get; set; }

        [Required]
        [StringLength(10)]
        public string Genero { get; set; } 

        [Required]
        [StringLength(200)]
        [Display(Name = "Dirección")]
        public string Direccion { get; set; }

        [Required]
        [StringLength(200)]
        [Display(Name = "Barrio")]
        public string Barrio { get; set; }

                
        public Municipio Municipio { get; set; }

        [Display(Name = "Municipio")]
        public int MunicipioId { get; set; }
        

        [Display(Name ="Telefono fijo")]
        public string TelefonoFijo { get; set; }

        [Required]
        [StringLength(30)]
        public string Celular { get; set; }

        [Required]
        [StringLength(254)]
        public string Correo { get; set; }

        public string Foto { get; set; }

        public string ImagenCC { get; set; }

        public string NumeroIdServicio { get; set; }

        [Required]
        public bool ResidenteAMB { get; set; }

        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        [DefaultValue("getutcdate()")]
        public DateTime? FechaInicioRegistro { get; set; }

        [DefaultValue(false)]
        public Boolean? Validado { get; set; }
                
        public DateTime? FechaFinalizaRegistro { get; set; }

        public int? Pin { get; set; }

    }

Open in new window

my view model
 public class NuevoUsuarioViewModel
    {

        //public Usuario Usuario { get; set; }
        [Required]
        [StringLength(80)]
        public string Nombres { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name = "Primer apellido")]
        public string PrimerApellido { get; set; }

        [Required]
        [StringLength(40)]
        [Display(Name = "Segundo apellido")]
        public string SegundoApellido { get; set; }

        [Required]
        [StringLength(30)]
        public string Cedula { get; set; }

        [Required]
        [Display(Name = "Fecha nacimiento ")]
        public DateTime FechaNacimiento { get; set; }

        [Required]
        [StringLength(5)]
        public string Rh { get; set; }

        [Required]
        [StringLength(10)]
        public string Genero { get; set; }

        [Required]
        [StringLength(200)]
        [Display(Name = "Dirección")]
        public string Direccion { get; set; }

        [Required]
        [StringLength(200)]
        [Display(Name = "Barrio")]
        public string Barrio { get; set; }


        [Display(Name = "Municipio")]
        public int MunicipioId { get; set; }


        [Display(Name = "Telefono fijo")]
        public string TelefonoFijo { get; set; }

        [Required]
        [StringLength(30)]
        public string Celular { get; set; }

        [Required]
        [StringLength(254)]
        public string Correo { get; set; }      

        [Required]
        public bool ResidenteAMB { get; set; }    

        [Display(Name = "Municipio")]
        public IEnumerable<BiciPublica.Models.Municipio> Municipios { get; set; }
        
    }

Open in new window


thanks in advance for your help.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial