0
votes

Hi I have Razor View that Generate a list of Addresses.
among all address the Phone Number Text Box is set as Required using MVC Data annotations.
But I have a Problem. Let say If my form is Rendering 3 Addresses for a particular Customer.
and customer is suppose to enter Three Phone Numbers.
If a customer doesn't enter number in any three text boxes, then all the text boxes will have validation messages saying Required. But If Customer enter a Phone Number in the First Text Box
Then All the text boxes are considered as validated and accepting the submit button. how can i fix this, so that the Required validation should work per individual Text Box.

1
Sounds like a model problem with your view. Can you post your code please.samack

1 Answers

0
votes

I got it fixed. what i did is

@html.Textboxfor(x=>x.Phone)

was generating common html name tag for all the Phone numbers in the list. and this was creating problem.
so what I did was instead of Html helpers, I wrote a standard input Tag

<input type= "text" value="@html.displayfor(x=>x.phone)" name="Phone @html(x=>x.phone)" />

and then used jQuery to Validate the Text box format and make it Required on change event.

Any ways thanks for your time.