Edit Signed that contains image

0

I have my model:

public class Produto 
{
   public int Id {get;set;}
   public string Nome {get;set;}
   public byte[] Imagem {get;set;}
}

How do I deal with it if it is "removing" or is it Editing (Replacing) the Product image? In my View:

  @Html.TextBoxFor(model => model.ImagemUpload, new { type = "file", @class = "filestyle form-control", @data_size = "sm" })

In my ViewModel I have the property

public HttpPostedFileBase ImagemUpload{ get; set; }

Which I check in the controller

if(model.ImagemUpload!= null) 
{
   Tem Imagem então salva/Edita
}

Here in Edit, New, it works, but how do I know when it's removing? So if it is removing the model.ImageUpload will come Null, and I need to delete the value that is with Byte [] in my table.

    
asked by anonymous 19.11.2014 / 20:21

1 answer

1

What I usually do in this case is a separate Ajax request at the moment it clicks on removing the image.

Another alternative is as soon as you click remove the image, you just delete it from the screen and add a <input type="hidden" name="imagem_excluida" value="true /> to the HTML. That way, when the form is submitted, you check this property to see if there has been an exclusion.

    
19.11.2014 / 21:11