开发者

Validating Dynamically added controls in ASP.NET MVC

I am trying to get validation to work for my very first ASP.NET MVC application. My problem is that all my controls were dynamically created. I have a Telerik tabstrip that has tabs that were dynamically (or programmatically) added. Each tab has a partial view with controls. The model that those controls map to is an Entity Framework model. I have decorated the model properties with annotations like “[Required]” (from System.ComponentModel.DataAnnotations;) and have added controls like Html.ValidationSummary and Html.ValidationMessageFor (for each field in your model) and I've been told it's supposed to work like magic! But it doesn't :(

Any ideas why my validation is not working? Do I h开发者_JAVA百科ave to do something special because the controls were created dynamically?

Steve

P.S. BTW, the server side validation works, but not the client side.


You need to store the datatypes and override the Validate() method on the Model. And verify casting works with the stored datatypes and the values of the dynamically created controls.. if the cast doesnt work return a validationresult.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜