【发布时间】:2014-04-16 23:12:19
【问题描述】:
我需要知道是否已在 Jasny Bootstrap 中删除了图像。我的保存和删除代码效果很好。问题是知道何时未设置图像,因为文件上传图像仅在存在时才转换为 HttpPostedFileBase。
类:
[NotMapped]
public HttpPostedFileBase Image { get; set; }
编辑视图:
@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>
}
保存代码:
if (data.Image == null) {
S3Utility.Delete(myObject.Id);
} else {
S3Utility.Upload(data.Image, myObject.Id);
}
所有这些都可以正常工作。如果有正确的图像,它甚至会加载图像(@imageUrl,我正在设置)。
问题是'Image' HttpPostedFileBase 在更新时总是为空。
有什么方法可以让我知道图像是否已被删除或设置?在 Jasny 中设置/删除图像时是否会更新该值?
我看到了这个帖子
http://www.jasny.net/articles/jasny-bootstrap-file-upload-with-existing-file/
但它没有转换为 Asp.Net MVC 4 和 HttpPostedFileBase。
【问题讨论】:
标签: c# twitter-bootstrap asp.net-mvc-4 razor jasny-bootstrap