I'm able to upload images and save them to a folder, but the only issue is storing the path in an SQL table. I want to save the Photo path to the database so that it can be displayed elsewhere. This is what I have so far.
Item class:
public class Item
{
public int ItemId { get; set; }
public string ItemName { get; set; }
public string Photo { get; set; }
}
Here's the Update action of the controller:
[HttpPost]
public ActionResult Update(item, HttpPostedFileBase files)
{
if (files != null && files.ContentLength > 0)
{
string fileName = Path.GetFileName(files.FileName);
var physicalPath = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
item.Photo = physicalPath;
files.SaveAs(physicalPath);
return Json(new { Photo = fileName }, "text/plain");
}
return Json(new[] { item });
}
Grid sample with upload widget integration:
http://jsbin.com/safog/1