Tuesday, December 31, 2013

How to enable Client Side Validation for Kendo UI


Recently I was struggling with using Jquery validation in ASP.NET MVC 4 application which used Kendo UI. Except the kendo DropDownLists in a particular view, every other control fired client validations. So it had to be a problem with Kendo libraries. Finally, I added below code snippet and it started working.

Kendo DropDown:

@(Html.Kendo().DropDownListFor(m => m.SiteID)
                            .Name("SiteID")
                            .OptionLabel("Select Below...")
                            .DataTextField("Text")
                            .DataValueField("Value")
                            .Value(Model.SiteID.ToString())
                            .DataSource(ds =>
                            {
                                ds.Read("ToolbarTemplate_Categories", "EnterNewDocumentVendor");
                            })
                        )

Jquery Code:

<script>

    $(document).ready(function () {

        $.validator.setDefaults({
            ignore: ""
        });

        $("#SiteID").kendoValidator();
 
    });
</script>

Following link would be useful for newer versions of Jquery.

http://stackoverflow.com/questions/8466643/jquery-validate-enable-validation-for-hidden-fields

No comments:
Write comments
Recommended Posts × +