Search code examples
asp.net-mvcunobtrusive-validation

jquery validate work for first input


In my View. Each field has validation. Here is some sample code...

@using (Html.BeginForm("About", "Home"))
{
<button>отправить</button>
for (int i = 0; i < 1000; i++)
{
    @Html.TextBoxFor(a => a.Number,new {Id=i,Name=i})

}
}

My model

   public class Class1
{
    [Required]
    public decimal Number { get; set; }
}

Jquery validate work for first input.have any ideas?


Solution

  • public class Class1
    {
        [Required]
        public decimal Number { get; set; }
    }
    
    public class Class2
    {
        public Class1[] items { get; set; }
    }
    

    View code:

    @model MvcApplication1.Models.Class2
    

    ...

    for (int i = 0; i < 10; i++)
    {
        @Html.TextBoxFor(m=>m.items[i].Number, new { Id = i, Name = i })
    
    }