How can i upload & Save image in Ms-sql server-2008 database. Using MVC create view and I using EntityFarmework Model First.
Zakir
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaganathan BantheswaranPosted Oct 31, 2013, 5:40 AM
Create a property in your respective viewmodel/model but not in EF model.
public HttpPostedFileBase PhotoUpload { get; set; }
Then add a input field in form,
@Html.TextBoxFor(m => m.PhotoUpload, new { type = "file" })
Then, in the controller action,
[HTTPPost]
public ActionResult SaveProfile(ProfileViewModel vm)
{
if (vm.PhotoUpload.ContentLength > 0) {
// A file was uploaded
var fileName = Path.GetFileName(vm.PhotoUpload.FileName);
var path = Path.Combine(Server.MapPath(uploadPath), fileName);
vm.PhotoUpload.SaveAs(path);
vm.Photo = uploadPath + fileName;
}
}
HanookPosted Oct 31, 2013, 5:24 AM
http://stackoverflow.com/questions/14583938/how-to-store-an-image-in-database-and-then-display-it-in-mvc
http://www.codeproject.com/Articles/658522/Storing-Images-in-SQL-Server-using-EF-and-ASP-NET