Here is the gist of what I am trying to achieve:
- Capture a webcam image from the Edit view. (working)
- Assign the image a file name and path. (working)
- Save the image to the images folder. (working)
- Store the path to the image in the database. (Not working)
Here is my Capture controller:
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;
}
And here is the Edit controller:
[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);
}
From my limited understanding it would be nice to pass the file path as a variable from the Capture void to the controller for binding to the model.
Thanks for your help.
Its working! Well I did it in a roundabout way and still happy to hear suggestions.
Heres the gist:
when I click the capture button i run the function:
Here is the Capture function(fairly standard - can someone tell me if I need document ready for this?)
Here is my controller, modified to accept the model ID as a string (have included the String to Bytes function for easy reference):
Now once capture has been clicked. The form can be submitted just as if you were submitting a strongly typed form.
There is a potential issue with this method
Im more than open to suggestions.