4

我有以下剑道上传控制

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

我的控制器:

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("");
}

我的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(", ");
}

如何在我的 javascript 中取回“ABC.jpg”作为我的文件名,而不是我选择上传的原始文件名?

4

1 回答 1

8

通过在我的控制器中执行此操作解决:

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

并在onSuccess函数中:

function onSuccess(e) {
    var imageName = e.response.ImageName;
}
于 2014-04-29T03:17:16.160 回答