kendo ui validate and upload images files

kendo ui validate and upload images files

Hi everyone, I am going to share the code sample to validate and upload the image files using kendo ui with jQuery. The code details as give below.

Table of Content

1. The cshtml razor view code.
2. jQuery and JavaScript code
3. MVC 5 controller code

The razor view

<div class="form-group">
   <label for="bio" class="control-label col-sm-2">Kendo ui Upload image file</label>
   <div class="col-sm-10">
           <input name="files" id="files" type="file" />                                                
   </div>
</div>

jQuery and JavaScript

<script type="text/javascript">
$(function () {
    //This used for check and validate image file.
    var onSelect = function (evn) {
        if (evn !== undefined && evn !== null) {
            $.each(evn.files, function (key, val) {
                if (val !== undefined) {
                    filepath = val.name;
                    var isValid = val.extension == ".JPG"
                                 || val.extension == ".JPEG"
                                 || val.extension == ".PNG"
                                 || val.extension == ".jpg"
                                 || val.extension == ".jpeg"
                                 || val.extension == ".png";                         

                    if (!isValid) {
                        evn.preventDefault();
                        showMSG($("#msg"), 'Please select only image files.');
                    }
                }
            });
        }
    };

    var onComplete = function () {
        $(".k-widget.k-upload").find("ul").remove();
        $(".k-upload-files.k-reset").find("li").remove();
    };

    $("#files").kendoUpload({
        async: {
            saveUrl: '@Url.Action("Submit", "UserProfile")',
            autoUpload: true
        },
        select: onSelect,
        complete : onComplete
    });
});

</script>

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.