我面临一些奇怪的问题。我在剃刀页面上的图像控件即使在Windows Azure存储服务器上替换为新图像后也会显示旧图像。但是当按下F5(刷新)按钮时,它会显示新的按钮。
流速:
这是razor页面的片段
Edit.cshtml
@model iSPYCMS.Models.iSPYAccount
<div class="form-group">
@Html.Label("Venue Logo")
@Html.TextBoxFor(model => model.Image.ImageFile, new { type = "file", id="file" })
</div>
<div>
<img src="@Model.Image.ImagePath" id="imgpreview" style="width:400px;height:200px"/>
</div>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imgpreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#file").change(function () {
readURL(this);
});
</script>
模型代码段
public class iSPYAccount
{
public int Id { get; set; }
public string AccountName { get; set; }
public iSPYImage Image { get; set; }
}
控制器
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult Edit()
{
//create the instance of DB Service
iSPYAccount ispyaccount = new iSPYAccount();
//Web service call and get the URL of Image from windows storage
// http://azurewebsites.mywebsite/1.jpg
ispyaccount.Image.ImagePath = Helper.GetImagePath(image.Name);
}
[HttpPost]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public ActionResult Edit(iSPYAccount account)
{
if (account.Image.ImageFile != null)
{
account.Image.imageDataURL = Helper.GetImageDataURL(account.Image.ImageFile);
account.Image.fileextension = System.IO.Path.GetExtension(account.Image.ImageFile.FileName);
//save image to windows azure storage
imageapi.SaveImage(account.Image.imageDataURLaccount.Image.fileextension);
return RedirectToAction("Edit");
}
}