2014-03-14 138 views
0

enter image description here清除mvc3中的缓存。

我使用SQL Server的上传图片和上传的图片会立即反映在网格below.my问题是当过我改变或编辑图片,图片将在数据库中更改,但网格显示之前我删除的图片。我必须注销并再次查看这些更改。有什么办法可以解决这个问题吗?每当网格重新加载时,是否有任何方法可以清除缓存?

+0

尝试刷新页面。不是最好的做法,但我认为会起作用。 –

回答

0

您可以尝试在下面的帖子中编写自己的属性,例如[no-cache],并且可以在控制器上使用它来防止缓存。

Prevent Caching in ASP.NET MVC for specific actions using an attribute

http://dotnetnsqlcorner.blogspot.co.uk/2012/09/disable-caching-for-controller-action.html?m=1

要禁用客户端缓存,你也可以在你的行动结果使用[outputcacheattattribute。以下文章可能会有帮助

[OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)] 

How can I disable client side and proxy caching in ASP.NET MVC?

有禁用缓存以及其他方式,,但我想上面的两种方法应该做的工作之一。希望这有助于

0

您可以将操作方法​​,并在你的Ajax调用创建除了cache: false无缓存行为过滤器的属性。

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] 
public sealed class NoCacheAttribute : ActionFilterAttribute 
{ 
    public override void OnResultExecuting(ResultExecutingContext filterContext) 
    { 
    filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
    filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false); 
    filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
    filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    filterContext.HttpContext.Response.Cache.SetNoStore(); 

    base.OnResultExecuting(filterContext); 
    } 
} 

这很好地解释了Here。希望能帮助到你。