bug - validation attributes are not applied to Editor

5 posts, 0 answers
  1. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2012

    Posted 01 Jul 2012 Link to this post

    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.
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 04 Jul 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2012

    Posted 04 Jul 2012 Link to this post

    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.
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 05 Jul 2012 Link to this post

    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!
  6. Matt
    Matt avatar
    1 posts
    Member since:
    Jul 2012

    Posted 05 Jul 2012 Link to this post

    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.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready