0

I have a classified ad View Model that is defined as:

public class ClassifiedAd
{
   public int ClassifiedAdId { get; set; }
   public string Title { get; set; }
   public string Text { get; set; }
   public HttpPostedFileBase ImageFile { get; set; }
}

As you can see, users can upload an image for the ad. This works fine during the creation of the ad.

However suppose I want to allow users to edit their classified ad, including the uploaded image. How am I supposed to populate the ImageFile property with the currently uploaded file when the HttpPostedFileBase class is abstract? How do I properly display the currently uploaded image and prevent the user from deleting it unintentionally and/or allow them to delete it properly?

Is there a way to create an instance of HttpPostedFileBase from a MemoryStream of byte array that I'm missing here or is there some other way to deal with this issue?

RickL
  • 3,318
  • 10
  • 38
  • 39
Marko
  • 12,543
  • 10
  • 48
  • 58
  • You can create a different ViewModel for the edit page and skip that field. – Anderson Fortaleza Oct 06 '14 at 14:33
  • Not sure what do you mean? Why would I skip that field I want them to be able to replace current image with another one or delete current image. How can I do that by skipping the field? – Marko Oct 06 '14 at 14:36
  • 1
    Notice that it's Http*Posted*FileBase. It only contains data that Is posted. It isn't something that can be edited. If the user wants to "edit" it, they upload a new file, which replaces it in the next post. There's no way for a user to see this data, unless you extract it and then provide it in a separate image download. – Erik Funkenbusch Oct 06 '14 at 15:11
  • @ErikFunkenbusch I see. So the only way would be for me to extend the model to where I have another property that contains current uploaded file name and then generate some mechanism to delete the file while the HttpPostedFileBase property would only be to upload a new file. Does this sound about right? – Marko Oct 06 '14 at 15:16

0 Answers0