Friday, May 11, 2012

Remove MVC Action from Cache

For removing the Cache from the action so it get refresh each time, use the below stuff
 
public class NoCacheAttribute : ActionFilterAttribute
{
    public override void OnActionExecuted ( ActionExecutedContext context )
    {
        context.HttpContext.Response.Cache.SetCacheability( HttpCacheability.NoCache );
    }
}

[HttpGet]
[NoCache]
public JsonResult GetSomeStuff ()
{
    ...
}

No comments:

Post a Comment