开发者

ASP.Net MVC 3.0 Razor Form Validate Required Field

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 w开发者_如何学JAVAill 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜