开发者

ASP.NET MVC2 Client Validation bug?

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜