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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book