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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:21:55+00:00 2026-05-13T13:21:55+00:00

My problem: I can’t get Data Annotations Client Validation to work with a List

  • 0

My problem:

I can’t get Data Annotations Client Validation to work with a List in my viewdata class.

The skinny:

In my view data class I have a List.

public class FriendsViewData
{
    public List<Person> people { get; set; }
}

I have all the properties of the class Person as required using Data Annotations.

public class Person
{
    [Required(ErrorMessage="First Name is required")]
    public string FirstName { get; set; }
}

In the View I loop the List like this:
…

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

<% Html.EnableClientValidation(); %>

<% using (Html.BeginForm()) {%>

<%
   for(int i=0; i < Model.people.Count; i++)
   {%>
       <div>
         <%= Html.TextBox(string.Format("people[{0}].FirstName",i), Model.people[i].FirstName)%>
         <%= Html.ValidationMessage(string.Format("people[{0}].FirstName", i))%>
       </div>
<% } %>

<input type="submit" value="Submit" />

<% } %>

Generated HTML:

<div>
    <input id="people_0__FirstName" name="people[0].FirstName" type="text" value="Name0" />
    <span class="field-validation-valid" id="form0_people_0__FirstName_validationMessage"></span>     
</div>

<div>
    <input id="people_1__FirstName" name="people[1].FirstName" type="text" value="Name1" />
    <span class="field-validation-valid" id="form0_people_1__FirstName_validationMessage"></span>     
</div>

<div>
    <input id="people_2__FirstName" name="people[2].FirstName" type="text" value="Name2" />
    <span class="field-validation-valid" id="form0_people_2__FirstName_validationMessage"></span>     
</div>

Result:

Didn’t work at all.

Other things I’ve tried:

Tried using these HTML Helper methods in the view instead:

    <div>
        <%= Html.TextBoxFor(model => model.people[i].FirstName) %>
        <%= Html.ValidationMessageFor(model => model.people[i].FirstName) %>
    </div>

Generated output:

       <div>  
           <input id="FirstName" name="FirstName" type="text" value="Name0" />  
           <span class="field-validation-valid" id="form0_FirstName_validationMessage"></span>  
       </div>  

       <div>  
           <input id="FirstName" name="FirstName" type="text" value="Name1" />  
           <span class="field-validation-valid" id="form0_FirstName_validationMessage"></span>  
       </div>  

       <div>  
           <input id="FirstName" name="FirstName" type="text" value="Name2" />  
           <span class="field-validation-valid" id="form0_FirstName_validationMessage"></span>  
       </div> 

Result:

Interestingly, when I trigger a validation on the first textbox, it fires simultaneously for all of the textboxes. The rest of the textboxes do not trigger validation at all.

Note all generated id and names for the textboxes and their corresponding error text span element, are all identical.

Does any know how to use Client Validation with a List in the view data, supporting ModelBinding?

Thanks!

  • 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-13T13:21:55+00:00Added an answer on May 13, 2026 at 1:21 pm

    Brad Wilson from the ASP.Net team answered my same question in the ASP.Net forums.

      <div>  
           <%= Html.TextBoxFor(model => model.people[i].FirstName) %>  
           <%= Html.ValidationMessageFor(model => model.people[i].FirstName) %>  
      </div>  
    

    This is the correct way to do it, but it’s broken right now, and will be fixed in the next drop.

    http://forums.asp.net/t/1518900.aspx

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

Sidebar

Related Questions

Hello! My problem can be described the following way: I have some data which
Problem Can't get prependTo() and slideDown() functions work together. Short Please take a look
Problem How can I do work in one thread and update a progressbar on
I have a problem and can't find a solution. I am making an accordion
I have a problem and can't solve it alone. My teacher gives me one
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
Problem: can't get image to the screen... ?? I am looking for a methodology
I have tried to understand and use urlencode, but the problem can't be solved.
My problem can be simplified down to making the following script work (which takes
My problem can be simplified to a List<> with X and Y coordinates that

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.