I want to show the picture in the preview after I click on edit button, but it gets a picture in binary form in the list and then passes it to ajax call through Json result after that it did not convert under ajax call.can anyone help me to sort out this problem.thanks
JS
function Edit(id) {
$("#submit").html("Update Record");
$.ajax({
type: 'GET',
url: '/Home/EditUser',
data: { userid:id},
success: function (data) {
var obj = JSON.parse(data);
$("#imgPreview").show();
$("#imageBrowes:file").html(obj.Image_ID);
$("#targetImg").attr('src', "data:image/gif;base64,{0}", obj.ImageTbl.ImageByte);
$("#CId").val(obj.Content_ID);
$("#title").val(obj.Title);
$("#desc").val(obj.Description);
$("#type option:selected").text(obj.TypeTbl.Name);
$("#type option:selected").val(obj.Type_ID);
$("#fromdate").val(obj.DateFrom);
$("#todate").val(obj.DateTo);
},
failure: function (responce) {
alert.responce("Record not Found");
}
});
}
Controller
public ActionResult EditUser(int userid)
{
ContentTbl model = db.ContentTbls.Where(x => x.Content_ID == userid).SingleOrDefault();
var editimg = model.Image_ID;
TempData["eimageid"] = editimg;
string value = string.Empty;
value = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
JsonResult json = Json(value, JsonRequestBehavior.AllowGet);
json.MaxJsonLength = int.MaxValue;
return json;
}
View
<div id="imgPreview" class="thumbnail" style="display:none">
<img class="img-responsive" id="targetImg" />
<div class="caption">
<span id="description"></span>
</div>
<a href="#" class="btn btn-danger" onclick="ClearPreview()"><iclass="glyphicon glyphicon-trash">Clear</i></a>
</div>