Code
div class="form-group">Code
@Html.LabelFor(model => model.Picture, htmlAttributes: new { @class = "control-label col-md-2" })Code
div class="col-md-10">Code
img src="data:image/jpeg;base64,@Convert.ToBase64String(Model.Picture,78,Model.Picture.Length-78 ,Code
Base64FormattingOptions.None)"Code
alt="Image" />Python
input type="file" name="ImageData" id="ImageData" />Code
div>Code
div>And this is the controller :
Code
[HttpPost]Code
public ActionResult Edit(Category selectedc)Code
{ if (ModelState.IsValid)Code
{ if (Request.Files.Count > 0)Code
{ selectedc.Picture = new byte[Request.Files[0].ContentLength];Code
Request.Files[0].InputStream.Read(selectedc.Picture, 0, Request.Files[0].ContentLength);Code
} dbNorthwindEntities db = new dbNorthwindEntities();Code
Category updatedc = db.Categories.Single(c => c.CategoryID == selectedc.CategoryID);Code
updatedc.CategoryID = selectedc.CategoryID;Code
updatedc.CategoryName = selectedc.CategoryName;Code
updatedc.Description = selectedc.Description;Code
updatedc.Picture = selectedc.Picture;Code
db.SaveChanges();Code
// return RedirectToAction("Index", new {id = selectedc})Code
return RedirectToAction("Index");Code
} return View();Code
}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.

Manav PandyaRank #166 · 14.3K reputationPosted May 11, 2017, 8:18 PM EDT
d gj60 reputationPosted May 11, 2017, 11:44 PM EDT