Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6340109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:46:32+00:00 2026-05-24T19:46:32+00:00

public class RegisterViewModel { //Plain POCO Properties public RegisterModel RegisterModel { get; set; }

  • 0
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; }
}

Here are those classes:

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 here’s how I call the 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 doens’t have any annotations itself? Where can I formally read about this? All I’ve managed to find online is the occassional blog or two but they online mention simple models, not ones that have a relationship with other objects such as this. A typical foreign key country to person relationship.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:46:33+00:00Added an answer on May 24, 2026 at 7:46 pm

    The view model RegisterViewModel doesn’t have any "simple" properties and the MVC framework doesn’t render complex properties unless we tell it how to render those. We have to create display templates for DisplayFor and editor template for EditorFor helpers. Check the ASP.NET MVC 2 Templates for details. Another link.

    Place your EditorTemplates in folders

    ~/Views/Shared/EditorTemplates
    or
    ~/Views/ControlerName/EditorTemplates
    

    RegisterModel.cshtml

    @model RegisterModel
    
    @Html.LabelFor(model => model.UserName)
    @Html.EditorFor(model => model.UserName)
    
    @Html.LabelFor(model => model.Email)
    @Html.EditorFor(model => model.Email)
    
    ...
    ...
    

    CityModel.cshtml

    @model CityModel
    
    @Html.LabelFor(model => model.CityId)
    @Html.EditorFor(model => model.CityId)
    
    @Html.LabelFor(model => model.Name)
    @Html.EditorFor(model => model.Name)
    

    CountryModel.cshtml

    @model CountryModel
    
    @Html.LabelFor(model => model.CountryId)
    @Html.EditorFor(model => model.CountryId)
    
    @Html.LabelFor(model => model.Name)
    @Html.EditorFor(model => model.Name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class InvestorMailing { public string To { get; set; } public IEnumerable<string> Attachments
public class Address { public string ZipCode {get; set;} } public class Customer {
public class Options { public FolderOption FolderOption { set; get; } public Options() {
public class Foo{ public string Prop1 {get;set;} public string Prop2 {get;set;} public Foo(Foo source)
public class Foo { public string Name { get; private set;} // <-- Because
public class MyClass { public string Name {get; KEYWORD set;} public MyClass(string name) {
public class ClassA { public string MyString {get; set;} } public class ClassB {
public class Emp { public int ID { get; set; } public string Name
public class Abbreviation { public string ShortName { get; set; } public string LongName
public class MyItem { public string Name { get; set; } public IList<MyItem> ListByName(string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.