我有以下Kendo上传控件
@(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”作为我的文件名而不是我选择上传的原始文件名?
答案 0 :(得分:8)
通过在我的控制器中执行此操作解决:
var newImageName = "123.jpg";
return Json(new { ImageName = newImageName }, "text/plain");
并在onSuccess
函数中:
function onSuccess(e) {
var imageName = e.response.ImageName;
}