1

I enable client validation using the Html.EnableClientValidation method in my view. This client-side validation works great for text boxes, but I think I might have found a bug when used with dropdownboxes.

If you use the following construction Html.DropDownList( name, data, "Please choose..." ) without any ViewData-item with that name then client-side validation works great. If you look at the generated HTML code you will see that ASP.NET generated ValidationRules for it in the JSON block.

However, if I add a ViewData-item with that name then the ValidationRules for the client validation is empty!

In both cases, server-side validation works as expected. Bug or is there something that I am missing?

1 Answer 1

1

The solution is simple:

<%= Html.DropDownList("Username", CType(ViewData("Data"), SelectList), "Please choose...")%>

Client-validation does not work if you do it like this:

<%= Html.DropDownList("Username", "Please choose...")%>

In both cases, I use the same code to construct the ViewData item but it only works with the first statement.

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

Comments

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.