This is a migrated thread and some comments may be shown as answers.

bug - validation attributes are not applied to Editor

4 Answers 241 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 01 Jul 2012, 07:39 PM
When using EditorFor any data annotations applied to the ViewModel such as Required, StringLength, etc are not added to the wrapped TextArea as data attributes, therefore no client validation is applied.

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 04 Jul 2012, 05:06 PM
Hello Matt,

The attributes will not be added if an actual instance of the model is not passed to the view. If this is not causing the problem in your scenario, I will need a sample project or the code you are using so I can check the setup.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Matt
Top achievements
Rank 1
answered on 04 Jul 2012, 06:06 PM
Hi Daniel,

Thanks for your reply. This problem only appears to occur when using editor templates for complex nested models. I've attached a completely stripped down project (even the Kendo css and js is not applied) containing an example view that exhibits this behaviour. The second Kendo rendered TextArea has no data validation attributes applied. The problem appears to occur in the Mvc Extensions at the point that the ViewComponentExtensions.GetUnobtrusiveValidationAttributes method is called. For some reason in the case of the example project that method is not returning any attributes (maybe the view model property names or field prefix are passed incorrectly?). Note that if you use a standard Html.TextAreaFor() as I have for the first text area it works as expected, leaving me to suspect that this is indeed a problem with the Kendo extensions.

In addition, this appears to be a problem with any control that is rendered in a nested view - not just the editor.
0
Daniel
Telerik team
answered on 05 Jul 2012, 10:55 AM
Hello Matt,

Thank you for providing a sample project. The problem occurs because the meta data from which the attributes can be obtained is different in this context. I am glad to inform you that this has been fixed and the changes will be applied in the official release of Kendo UI for ASP.NET MVC.
For now you can use the HtmlAttributes method to set the validation attributes e.g.

@Html.Kendo().EditorFor(x => x.Test2).HtmlAttributes(Html.GetUnobtrusiveValidationAttributes("Test2"))

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Matt
Top achievements
Rank 1
answered on 05 Jul 2012, 11:28 AM
Thanks Daniel, that's great news. As a side note it might also be worth checking this for the standard Telerik MVC extensions, as I could reproduce it with those last time I checked.
Tags
Editor
Asked by
Matt
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Matt
Top achievements
Rank 1
Share this question
or