我目前正在使用Kendo UI将文件上传到使用MVC3和Razor和Entity Framework的数据库.我在我的网站的几个区域工作得很好,除非我需要限制它只允许单一上传.我有多个设置为false,我需要禁止多个选择,但仍允许用户多次单击选择按钮添加文件,违反了DB中此字段的要求.
我尝试了一些我认为在他们的网站上找到的建议,但他们指的是当前请求中发送的当前所选项目,而不是整个上传列表(见下图).
<script type="text/javascript">
function singleFile(e) {
var files = e.files;
if (e.files.length > 1) {
alert('Only one file may be uploaded, cancelling operation...');
e.preventDefault();
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
@(Html.Kendo().Upload()
.Name("resumeAttachments")
.Multiple(false)
.Async(async => async
.Save("ResumeSave", "File")
)
.Events(c => c
.Upload("resumeOnUpload")
)
.Events(c => c
.Success("resumeOnSuccess")
)
.Events(c => c
.Complete("singleFile")
)
)
Run Code Online (Sandbox Code Playgroud)
