0

I know that this code works just fine to validate field.

<%: Html.TextBox("FirstName", ViewData["FirstName"], new { maxlength = 200 })%> 
<%: Html.ValidationMessage("FirstName", "*")%>

And I guess that possible that dynamic generated name of the control to validate should work as well. But it does't.

 <% for (int i = 0; i < numberOfGuests; i++)
 { %>                     

 First Name:  <%:  Html.TextBox("FirstName_" + i) %> 
 <%: Html.ValidationMessage("FirstName_" + i, "*") %>  

 <% } %> 

So at this case no validation at all. Am I missing something?

1 Answer 1

1

You should implement the validation logic for that. without implementing a validation, Html.ValidationMessage() method is no use at all.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah... I know that I can use code behind for that. I just guessed that this should work Html.ValidationMessage("FirstName_" + i, "*") but thanks anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.