return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>c# - KendoUI: How to get new file name in javascript after renaming uploaded file in controller - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - KendoUI: How to get new file name in javascript after renaming uploaded file in controller - Stack Overflow

programmeradmin0浏览0评论

I have the following Kendo upload control

        @(Html.Kendo().Upload()
                      .Name("files")
                      .Async(a => a
                      .Save("SaveBackgroundImage", "Plans")
                      .AutoUpload(true))
                      .Multiple(false)
        .Events(events => events.Success("onSuccess")))

My controller:

public ActionResult SaveBackgroundImage(IEnumerable<HttpPostedFileBase> floorplanFiles, string floorplanId)
{
        foreach (var file in files)
        {                   
            string fileName = "ABC.jpg" //this will be random                      
            var physicalPath = Path.Combine(Server.MapPath("~/Images/Floorplans/Fullsize"), fileName);
            file.SaveAs(physicalPath);
        }
    // Return an empty string to signify success
    return Content("");
}

My javascript:

function onSuccess(e) {
    var filename = getFileInfo(e);
    alert(filename);
}

function getFileInfo(e) {
    return $.map(e.files, function (file) {
        var info = file.name;
        return info;
    }).join(", ");
}

How do I get back "ABC.jpg" as my filename in my javascript instead of the original filename that I select to upload?

I have the following Kendo upload control

        @(Html.Kendo().Upload()
                      .Name("files")
                      .Async(a => a
                      .Save("SaveBackgroundImage", "Plans")
                      .AutoUpload(true))
                      .Multiple(false)
        .Events(events => events.Success("onSuccess")))

My controller:

public ActionResult SaveBackgroundImage(IEnumerable<HttpPostedFileBase> floorplanFiles, string floorplanId)
{
        foreach (var file in files)
        {                   
            string fileName = "ABC.jpg" //this will be random                      
            var physicalPath = Path.Combine(Server.MapPath("~/Images/Floorplans/Fullsize"), fileName);
            file.SaveAs(physicalPath);
        }
    // Return an empty string to signify success
    return Content("");
}

My javascript:

function onSuccess(e) {
    var filename = getFileInfo(e);
    alert(filename);
}

function getFileInfo(e) {
    return $.map(e.files, function (file) {
        var info = file.name;
        return info;
    }).join(", ");
}

How do I get back "ABC.jpg" as my filename in my javascript instead of the original filename that I select to upload?

Share Improve this question asked Apr 26, 2014 at 15:47 Null ReferenceNull Reference 11.4k41 gold badges111 silver badges187 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Solved by doing this in my controller:

var newImageName = "123.jpg";
return Json(new { ImageName = newImageName  }, "text/plain");

and in the onSuccess function:

function onSuccess(e) {
    var imageName = e.response.ImageName;
}
发布评论

评论列表(0)

  1. 暂无评论