public class RegisterViewModel { //Plain POCO Properties public RegisterModel RegisterModel { get; set; } //Meant to be used in SelectLists. public IEnumerable<CityModel> Cities { get; set; } public IEnumerable<CountryModel> Countries { get; set; } }
These classes are:
public class RegisterModel { [Required] [Display(Name = "Usuario")] public string UserName { get; set; } [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Correo")] public string Email { get; set; } [Required] [StringLength(100, ErrorMessage = "Su {0} debe tener al menos {2} caracteres.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Contraseña")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirme Su Contraseña")] [Compare("Password", ErrorMessage = "Sus contraseñas no son las mismas.")] public string ConfirmPassword { get; set; } [Required] [Display(Name = "Nombre")] public string Nombre { get; set; } [Required] [Display(Name = "Apellido")] public string Apellido { get; set; } [Required] [Display(Name = "Direccion")] public string Address { get; set; } [Required] [Display(Name = "Telefono Fijo")] public string Telephone { get; set; } [Required] [Display(Name = "Celular")] public string MobilePhone { get; set; } [Required] [Display(Name = "Fecha de Nacimiento")] public DateTime DateOfBirth { get; set; } [Required] [Display(Name = "Soy:")] public bool Sex { get; set; } [Required] [Display(Name = "Carnet")] public int Carnet { get; set; } } public class CityModel { [HiddenInput(DisplayValue = false)] public int CityId { get; set; } [Required] [Display(Name = "Ciudad")] public string Name { get; set; } } public class CountryModel { [HiddenInput(DisplayValue = false)] public int CountryId { get; set; } [Required] [Display(Name = "Pais")] public string Name { get; set; } }
And this is how I call RegisterViewModel in my view:
@model Foodiggly.WebUI.Models.RegisterViewModel @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>RegisterViewModel</legend> @Html.EditorForModel() <p> <input type="submit" value="Create" /> </p> </fieldset> }
Is this error caused because my ViewModel does not have any annotations? Where can I officially read about it? All I managed to find on the Internet is a separate blog or two, but they mention simple models online, and not those that relate to other objects such as this. Typical external connection between countries and people.
Any ideas?
source share