这是我要实现的目标的要点:
- 从编辑视图捕获网络摄像头图像。(在职的)
- 为图像分配文件名和路径。(在职的)
- 将图像保存到图像文件夹。(在职的)
- 将图像的路径存储在数据库中。(不工作)
这是我的捕获控制器:
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 传递给控制器以绑定到模型。
谢谢你的帮助。