我难倒上的图像问题...继承人的内幕。MVC 3更新上传的图片
在我的布局,我有作为一个标志......然而,在管理视图有上传新徽标的能力,它简单地替换当前一个具有完全相同的名称的图像。回发后,即使保存更新的图像,图像在布局上也不会更改为更新的图像。如果我刷新页面使用Ctrl和F5,缓存消失了,我可以看到新的形象,但我需要的是更加自动化。
我的继承人在布局
<img src="@Url.Content("~/Content/themes/base/images/Client_Logo.jpg")" id="ClientLogo" alt="" width="227" height="130" style="float: left;" />
继承人的管理视图
@using (Html.BeginForm("Admin", "Home", FormMethod.Post, new { @encType = "multipart/form-data" }))
{
<fieldset>
<legend>Logo Management</legend>
<p>
<input type="file" name="FileUpload" />
</p>
<p>
<input type="submit" value="Upload" />
</p>
</fieldset>
}
最后的动作img标签
[Authorize]
[HttpPost]
public ActionResult Admin()
try
{
HttpPostedFileBase file = Request.Files[0];
if (file != null)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Content/themes/base/images"), fileName);
file.SaveAs(path);
System.IO.File.Delete(Path.Combine(Server.MapPath("~/Content/themes/base/images"), "Client_Logo.jpg"));
System.IO.File.Move(Path.Combine(Server.MapPath("~/Content/themes/base/images"), fileName), Path.Combine(Server.MapPath("~/Content/themes/base/images"), "Client_Logo.jpg"));
}
else
{
ModelState.AddModelError("uploadError", "There is a problem uploading the file.");
}
}
catch (Exception e)
{
ModelState.AddModelError("uploadError", e);
}
return View();
是什么大家都建议以刷新办上传图像后返回视图时布局中的图像?
干杯。
我相信,但是这会工作,我刚刚去了,原来在web.config文件cacheing关闭...最好我不需要高速缓存,因为它不会被用来作为互联网应用,只是内联网。 – bl4kh4k 2012-03-15 18:46:04