按文件上传文件正在我的代码示例中正确运行但我想在输入其他数据字段时保留后期操作 从输入,文本等输入我的数据库 如何从后期操作中控制此操作或如何在按下按钮提交时将拖动的图像保持为对象,以便转到Actionresult?
这是控制器:
[HttpPost]
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
if (!Directory.Exists(Server.MapPath("~/TempImages/")) || files !=null)
{
string TempPath = Server.MapPath("~/TempImages/");
foreach (HttpPostedFileBase file in files)
{
string filePath = Path.Combine(TempPath, file.FileName);
System.IO.File.WriteAllBytes(filePath, ReadData(file.InputStream));
file.SaveAs(filePath);
}
}
return Json("Successfully Uploaded .");
}
private byte[] ReadData(Stream stream)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
更新
<script src="~/Scripts/jquery.filedrop.js"></script>
<script src="~/Scripts/jquery.filedrop.support.js"></script>
<h2>File Drag & Drop Upload Demo</h2>
<div id='dropbox'>
<span class="message">Drop images here to upload. <br /><i>(they will only be visible to you)</i></span>