d gj

d gj

  • NA
  • 64
  • 2.7k

jpg/png dont show in runtime

Apr 7 2017 4:50 AM
This is the view :

<div class="form-group">             
@Html.LabelFor(model => model.Picture, htmlAttributes: new { @class = "control-label col-md-2" })    
         <div class="col-md-10">      
           <img src="data:image/jpeg;base64,@Convert.ToBase64String(Model.Picture,78,Model.Picture.Length-78 ,
           Base64FormattingOptions.None)"         
             alt="Image" />               
   <input type="file" name="ImageData" id="ImageData" />         
      div>      
   div>


And this is the controller :

[HttpPost]     
   public ActionResult Edit(Category selectedc)   
     {            if (ModelState.IsValid)    
        {                if (Request.Files.Count > 0)       
         {                    selectedc.Picture = new byte[Request.Files[0].ContentLength];                  
  Request.Files[0].InputStream.Read(selectedc.Picture, 0, Request.Files[0].ContentLength);               
     }                dbNorthwindEntities db = new dbNorthwindEntities();    
            Category updatedc = db.Categories.Single(c => c.CategoryID == selectedc.CategoryID);         
       updatedc.CategoryID = selectedc.CategoryID;       
         updatedc.CategoryName = selectedc.CategoryName;   
             updatedc.Description = selectedc.Description;              
  updatedc.Picture = selectedc.Picture;   
             db.SaveChanges();            
    //  return  RedirectToAction("Index",  new {id = selectedc})       
         return RedirectToAction("Index");   
           }            return View();    
    }

Northwind Category table has a field called PICTURE of type Image . I can retrieve Northwind pictures from database .However when i try to upload any png/jpg picture from my machine , it saves , but it doesnt show in the page , it displays just Image text . 

Any help ?!

Thank u.

Answers (2)