0

My application is developed in asp.net c#. I have a form to update data with image, this is working fine and record is getting saved in database perfectly. In a scenario where my form is in edit mode, i am retrieving record from database using ajax with JSON response and binding all input fields with JSON response. The problem here is i have a IMAGE location in response (~/assets/gallery/popup/image.jpg), how can i assign it back to input file type field with image preview, to show previously selected image. Suggest me some ideas or alternative approach.

If assigning file location back to field is not possible, then how should i proceed with this, to show previously selected image

Thanks

Dave
  • 4,376
  • 3
  • 24
  • 37
  • possible duplicate of [How to set a value to a file input in HTML?](http://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html) – Arun P Johny Apr 26 '14 at 11:37
  • thanks for response Arun,, how to deal with this ? – Dave Apr 26 '14 at 11:38
  • If you just need a preview, there are ways to do that on the clientside, but setting the value of the file input back to the fake filepath doesn't really work. – adeneo Apr 26 '14 at 11:41

1 Answers1

1

Just send back the image URL to the client as a callback. Then use javascript to load the image by adding this tag:

$("#previewDivId").append("<img src='" + ImageURL + "' />");

Remember to replace previewDivId and ImageURL in the above code.

aztrorisk
  • 161
  • 4
  • 10