Prasanna Kumari

Prasanna Kumari

  • NA
  • 1
  • 2.8k

How to save images to the mysql database using asp.net mvc3

May 22 2012 5:52 AM

Helo,Iam building an asp.net mvc3 application.Iam working on project saving images to the mysql database.I build an application but in that in view My view page looks like<form action="../../Controllers/MapController.cs" method="post" enctype="multipart/form-data"> <div> <fieldset> <legend>Upload Image</legend>         @Html.Label("Title") @Html.Editor("fileTitle")<br /> Upload File: <input type="file" name="test" /> <p> <input type="submit" value="Create"/> </p> </fieldset> </div> </form>  
The controller looks like 
[HttpPost]      
   public ActionResult Create(string fileTitle)    
     {                
HttpPostedFileBase file = Request.Files[0];              
   byte[] imageSize = new byte[file.ContentLength];                
file.InputStream.Read(imageSize, 0, (int)file.ContentLength);                
Image g = new Image();                  
 g.Name = file.FileName.Split('\\').Last();
g.Size = file.ContentLength; g.Title = fileTitle;                   
 g.Id=4; g.Image1 = imageSize;
try{
this.dbContext.Add(g);                
dbContext.SaveChanges();                
return RedirectToAction("Index");            
}            
catch (Exception e) {              
  ModelState.AddModelError("uploadError", e);           
  }
return View();        
}  
when i run this i get connection set up error on enctype when i remove that enctype in view page i get server error in/ application path is not found .Iam trying for so many days .So i want this project very badly.Please give sample code or suggestions
Regards
Prasanna