schema: {
model: {
fields: {
Age: {
type:
"number"
}
}
}
}
if
(field ==
"Age"
)
columns[currentCol].template =
"#= (Age == null) ? ' ' : Age #"
;
Hi,
I am using Kendo UI async upload for uploading files to our storage.
I am retrieving the Modified file name after each upload and return to the UI. (for unique identification)
Since I am having multiple upload I need a facility to delete any row after uploading it. (which will delete from the storage using the controller method)
but when I try to delete the second row onwards I am getting the concatenated file names in the controller instead of the selected file name.
So I tried different things. but no luck. (including the onComplete(e) function given below)
So all I need is find the index of the Remove button clicked. Then I can find the actual <li> element and set its value as the corresponding file name.
Please help.. Please let me know if you need any more information. Thanks.
This is my code :
View
<section>
<script>
function onSuccess(e) {
if (e.operation == 'upload') {
if (e.response.data != '') {
$('.k-upload-files.k-reset').each(function () {
$(this).find('span.k-filename').each(function (index) {
var current = $(this);
if (current.children().size() > 0) {
var fileName = e.response.data[0].FileName;
if (current.children().size() == 1 && index == 0) {
$(this).text('');
$(this).text(fileName);
}
else if (current.children().size() <= index) {
$(this).text('');
$(this).text(fileName);
}
}
});
});
}
}
}
function onComplete(e) {
$('.k-upload-files.k-reset').each(function () {
$(this).find('span.k-filename').each(function (index) {
var current = $(this);
var fileName = current.text();
if (fileName != '') {
if (e.files != undefined) {
if (e.files[index] != undefined) {
e.files[index].name = fileName;
}
}
}
});
});
}
function onFileRemove(e) {
// Here I need to find the index of the Remove button clicked <li>.
var fileName = $("span.k-filename").text();
if (fileName != '') {
e.files[0].name = fileName;
}
}
</script>
<div>
@(Html.Kendo().Upload()
.Name("files")
.Messages(msg => msg
.DropFilesHere("Please drop the files here to upload..")
.Select("Please select the file to upload by clicking the Select File button..<br /><br />")
.StatusUploaded("File Successfully Uploaded to Azure Storage.. File Name : ")
.StatusFailed("File Uploading Failed..")
.StatusUploading("Uploading the file now....."))
.ShowFileList(true)
.Multiple(true)
.Async(a => a
.Save("Save", "Upload")
.AutoUpload(true)
.Remove("Remove", "Upload"))
.Events(events => events
.Success("onSuccess")
.Complete("onComplete")
.Remove("onFileRemove")
)
)
</div>
</section>
Controller
=======
public ActionResult Save(IEnumerable<HttpPostedFileBase> files)
{
// getting the filename after uploading and send back to the client.
return Json(
new
{
status = 1,
data = new[] {
new { FileName = fileName }
}
}, "text/plain");
}
public ActionResult Remove(string[] fileNames)
{
var errors = new List<string>();
if (fileNames != null)
{
foreach (var fileName in fileNames)
{
errors = DeleteFroStorage(filename); //here I am getting myfile4V_6.txtmyfile4V_7.txt” when I upload 2 txt files instead of the selected file name
}
}
return Json(
new
{
status = 1,
data = new[] {
new { Error = errors }
}
}, "text/plain");
}
My rendered html looks like this.
<div class="k-widget k-upload">
<div class="k-dropzone">
<div class="k-button k-upload-button">
<input id="files" name="files" type="file" data-role="upload" multiple="multiple" autocomplete="off" />
</div>
<em>Please drop the files here to upload..</em>
</div>
<ul class="k-upload-files k-reset">
<li class="k-file">
<span class="k-icon k-success">File Successfully Uploaded to Azure Storage.. File Name : </span>
<span class="k-filename" title="myfile4.txt">myfile4V_6.txt</span>
<button type="button" class="k-button k-button-icontext k-upload-action">
<span class="k-icon k-delete"></span>Remove
</button>
</li>
<li class="k-file">
<span class="k-icon k-success">File Successfully Uploaded to Azure Storage.. File Name : </span>
<span class="k-filename" title="myfile4.txt">myfile4V_7.txt</span>
<button type="button" class="k-button k-button-icontext k-upload-action">
<span class="k-icon k-delete"></span>Remove
</button>
</li>
</ul>
</div>
@@font-face {
font-family
:
"fontello"
;
src
:
url
(@Url.Content(
"~/Content/font.ttf"
)
format
(
"truetype"
),
url
(@Url.Content(
"~/Content/font.woff"
)
format
(
"woff"
);
}
.km-androidicon:after
.km-androidicon:before {
content
:
'\26'
;
}
.km-appstoreicon:after
.km-appstoreicon:before {
content
:
'\41'
;
}
<
div
data-role
=
"layout"
data-id
=
"mobile-tabstrip"
>
<
div
data-role
=
"footer"
>
<
div
data-role
=
"tabstrip"
>
<
a
href
=
"#tabstrip-iOS"
data-icon
=
"androidicon"
>iOS</
a
>
<
a
href
=
"#tabstrip-Android"
data-icon
=
"appstoreicon"
>Android</
a
>
</
div
>
</
div
>
</
div
>