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