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 7191893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:49:30+00:00 2026-05-28T19:49:30+00:00

I have a RegisterModel, composed of 5 SecretQuestionAndAnswerModel models public class RegisterModel { public

  • 0

I have a RegisterModel, composed of 5 SecretQuestionAndAnswerModel models

public class RegisterModel
{
    public SecretQuestionAndAnswerModel SecretQuestion1 { get; set; }
    public SecretQuestionAndAnswerModel SecretQuestion2 { get; set; }
    public SecretQuestionAndAnswerModel SecretQuestion3 { get; set; }
    public SecretQuestionAndAnswerModel SecretQuestion4 { get; set; }
    public SecretQuestionAndAnswerModel SecretQuestion5 { get; set; }
}

and

public class SecretQuestionAndAnswerModel
{
        public SecretQuestionTypeModel Type { get; set; }

        [Required(ErrorMessage = "Please choose a question.")]
        public int Id { get; set; }
        public string Question { get; set; }

        [Required]
        [StringLength(20)]
        public string Answer { get; set; }

        [Display(Name = "Select Question")]
        public IEnumerable<SelectListItem> DefaultQuestions { get; set; }
}

On my main Register.cshtml, I include each question like this:

@Html.Partial("_QuestionAndAnswer", Model.SecretQuestion1, new ViewDataDictionary { { "Index", 1 }})

and that partial looks like:

<div class="input">
        @{
            @Html.DropDownListFor(m => Model.Id, Model.DefaultQuestions, "(Please choose one)") 
            @Html.ValidationMessageFor(m => Model.Id)

            @Html.TextBoxFor(m => m.Answer) 
            @Html.ValidationMessageFor(m => m.Answer)
        }
</div>

But on validation, all 5 questions behave as one: in other words if I select a question and type in an answer for the 1st secret question then they all pass validation, and vice versa…

Also, on posting to the HttpPost Register method

public ActionResult Register(RegisterModel model) { ...

the model.SecretQuestion1 is always null. All of them are. How do you do this sort of nested model-binding? I thought this would work ok.

  • 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-28T19:49:31+00:00Added an answer on May 28, 2026 at 7:49 pm

    The reason is pretty obvious if you look at the generated HTML. Each item has the same ID, and the same name. There is no easy way for the model binder to tell which is which.

    This is a prime example of the difference between a partial view, and a template. Templates have extra logic to deal with this situation.

    You should, instead create a SecretQuestionAndAnswerModel template and use

    @EditorFor(x => x.SecretQuestion1)
    

    If you are unsure of how templates work, read this:

    http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model: [Validator(typeof(RegisterValidator))] public class RegisterModel { public string Name { get; set;
Here's my model: [Required] [Display(Name = "I'm a:")] public bool Sex { get; set;
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a RegisterModel view model I use for my new account registration page.
I have a simple Model that is the default RegisterModel and upon creating a
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.