【发布时间】:2016-11-02 15:19:08
【问题描述】:
这是我想要实现的要点:
- 从“编辑”视图捕获网络摄像头图像。 (工作)
- 为图像分配文件名和路径。 (工作)
- 将图像保存到图像文件夹。 (工作)
- 将图像的路径存储在数据库中。 (不工作)
这是我的 Capture 控制器:
public void Capture(String FileLocation)
{
//var FileLocation = Server.MapPath("~/Images/test.jpg");
var stream = Request.InputStream;
string dump;
using (var reader = new StreamReader(stream))
dump = reader.ReadToEnd();
if (System.IO.File.Exists(FileLocation))
{
System.IO.File.Delete(FileLocation);
System.IO.File.WriteAllBytes(FileLocation, String_To_Bytes2(dump));
}
else System.IO.File.WriteAllBytes(FileLocation, String_To_Bytes2(dump));
return;
}
这里是编辑控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(TrappingEvent trappingevent)
{
if (ModelState.IsValid)
{
db.Entry(trappingevent).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.PersonId = new SelectList(db.People, "Id", "First_Name", trappingevent.PersonId);
return View(trappingevent);
}
根据我有限的理解,最好将文件路径作为变量从 Capture void 传递给控制器以绑定到模型。
感谢您的帮助。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 webcam-capture