简体   繁体   English

Kendo UI Image Upload文件类型的限制无效

[英]Kendo UI Image Upload Restriction for file type isn't working

I want to restrict image upload to only jpg images using the kendo UI for ASP .NET MVC3. 我想使用Windows .NET MVC3的kendo UI将图像上传限制为仅jpg图像。 However, when I followed the example here ,even with my manipulation below, it keeps alerting "please upload jpg image files" even when I uploaded a jpg file! 但是,当我按照这里例子 ,即使我下面的操作,它仍然警告“请上传jpg图像文件”,即使我上传了一个jpg文件! In fact, it makes me select all kinds of images. 事实上,它让我选择各种图像。 How can I change it so that I can only upload jpg images and if I upload png or other type of image files, it should alert, to only upload jpg images. 如何更改它以便我只能上传jpg图像,如果我上传png或其他类型的图像文件,它应该提醒,只上传jpg图像。

I put this into one of my views: 我把它放在我的一个观点中:

<script>
var onSelect = function (e) {
    $.each(e.files, function (index, value) {
        var ok = value.extension == ".JPG"
                 || value.extension == ".JPEG"
                 || value.extension == ".jpg"
                 || value.extension == ".jpeg";

        if (value.extension != ok) {
            e.preventDefault();
            alert("Please upload jpg image files");
        }
    });
};

// initialize and configure an Upload widget with a select event handler
$("#photos").kendoUpload({
    select: onSelect
});

You have a type-o: 你有一个类型o:

value.expresion == ".jpg"

Should be: 应该:

value.expression == ".jpg"

Notice you are missing an 's' 注意你错过了's'

EDIT 编辑

value.extension is a string which contains the extension. value.extension是一个包含扩展名的字符串。 And ok is a boolean which determines if the correct extension was provided, so what you want to use to determine if to display the alert should be displayed needs to be udpated: ok是一个布尔值,用于确定是否提供了正确的扩展名,因此您需要使用以确定是否显示警报的内容需要显示:

if (!ok) {
   e.preventDefault();
   alert("Please upload jpg image files");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM