如何将Kendo上传限制为CSV文件?
剃刀:
@(Html.Kendo().Upload()
.Name("import-file")
.Multiple(false)
.ShowFileList(true)
.Async(a => a
.Save("Save", "Import")
.Remove("Remove", "Import")
.AutoUpload(false)
)
.Events(events => events.Select("App.Import.select"))
)
使用Javascript:
Import: {
select: function (event) {
$.each(event.files, function (index, value) {
if (value.extension !== '.csv') {
alert("not allowed!");
}
console.log("Name: " + value.name);
console.log("Size: " + value.size + " bytes");
console.log("Extension: " + value.extension);
});
var breakPoint = 0;
}
}
我的想法是删除select事件中的文件。我怎么能做到这一点?
此致 马尔科
答案 0 :(得分:4)
根据文档here,您应该取消活动(e.preventDefault()
)。
因此,由于您不允许多个文件选择,您应该做的是:
select: function (event) {
var notAllowed = false;
$.each(event.files, function (index, value) {
if (value.extension !== '.csv') {
alert("not allowed!");
notAllowed = true;
}
console.log("Name: " + value.name);
console.log("Size: " + value.size + " bytes");
console.log("Extension: " + value.extension);
});
var breakPoint = 0;
if (notAllowed == true) e.preventDefault();
}