python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions