Sag*_*gar 1 asp.net-mvc jquery-ui kendo-ui
我是kendo ui的新手,我在我的asp.net mvc应用程序中使用文件上传插件.一切都像梦一样.但我有一个额外的要求.当我上传文件时,我正在为图像文件分配一个唯一的图像guid并上传然后返回到回调函数.这是我的代码.
<script type="text/javascript">
$(document).ready(function () {
$("#attachments").kendoUpload({
async: {
saveUrl: '@Url.Action("UploadBlogImages", "Blog")',
removeUrl: '@Url.Action("Remove", "Blog")',
autoUpload: true
},
success: function (data) {
var imageGuids = data.response;
$.each(imageGuids, function (index, imageGuid) {
$('#form_uploadPic').append('<input type="hidden" value=' + imageGuid + 'name="ImgGuid">');
});
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我需要删除的文件,当用户点击删除按钮,但我的问题是,在默认情况下删除按钮传递文件的名称(这是在上传时使用)作为文件名delete.But我重新命名上传到服务器之前的文件.我正在为文件分配一个唯一的guid.我已经将guid返回给成功函数.我如何配置以便删除按钮将该guid传递给服务器以删除文件.
谢谢,S
另一种选择是将id添加到文件对象本身,因此在onSuccess处理程序中添加以下内容:
function onUploadSuccess(e) {
//add the id returned in the json from the upload server script
e.files[0].id=e.response.id;
}
Run Code Online (Sandbox Code Playgroud)
然后在删除处理程序中将名称更改为id:
function onUploadRemove(e) {
var files = e.files;
for(i=0;i <files.length;i++){
//replace the name with the id added to the object
files[i].name=files[i].id;
}
}
Run Code Online (Sandbox Code Playgroud)
设置如下:
$("input[type='file']").kendoUpload(
{
async: {
saveUrl: "url",
removeUrl: "url",
removeField: "files"
},
success: onUploadSuccess,
remove: onUploadRemove
}
);
Run Code Online (Sandbox Code Playgroud)
适用于最新的kendoUI
| 归档时间: |
|
| 查看次数: |
7985 次 |
| 最近记录: |