I need to know if an image has been removed in Jasny Bootstrap. My saving and removing code works great. The problem is knowing when the image isn't set bc the file upload image only translated to an HttpPostedFileBase when one exists.
Class:
[NotMapped]
public HttpPostedFileBase Image { get; set; }
Edit View:
@using (Html.BeginForm("Edit", "MyObject", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<div class="field">
<div class="fileinput @imageClass" data-provides="fileinput" data-name="Image">
<div class="fileinput-new thumbnail" style="width: 150px; height: 150px;">
<img src="@MyNamespace.Components.S3Utility.DefaultImageUrl">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 350px; max-height: 350px;">
<img src="@imageUrl">
</div>
<div>
<span class="btn btn-default btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="Image">
</span>
<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
</div>
}
Save Code:
if (data.Image == null) {
S3Utility.Delete(myObject.Id);
} else {
S3Utility.Upload(data.Image, myObject.Id);
}
All of that works fine. It even loads up the image if there is one properly (@imageUrl, which I'm setting).
The problem is that 'Image' HttpPostedFileBase is always null on update.
Is there some way I can know if an image has been removed or is set? And have that value be updated on setting/removing the image in Jasny?
I saw this post
http://www.jasny.net/articles/jasny-bootstrap-file-upload-with-existing-file/
but it didn't translate to Asp.Net MVC 4 and HttpPostedFileBase.