Is it possible to use OutputCache on mvc JsonResult controller methods?
Asked Answered
H

1

14

I am trying to do this, and it leads to result with contentlen 0

It looks like:

[OutputCache(Duration = 36000)]
public JsonResult GetFileClasses() 
{
   return this.Json(TopicConfig.FileExtensionsSettings.List)
}

Any ideas?

Halsted answered 15/1, 2010 at 20:29 Comment(1)
And yes, without OutputCache everything works greatHalsted
U
16

In OutputCacheAttribute you must also specify , VaryByParam parameter. Otherwise you'll get this exception on result processing System.Web.HttpException: The directive or the configuration settings profile must specify the 'varyByParam' attribute. You can try to add this parameter and see if it works.

Udell answered 19/1, 2010 at 14:42 Comment(1)
To clarify: [OutputCache(Duration=36000, VaryByParam="")]. Thank you Branislav, this has been driving me nuts as well!!!Bonnes

© 2022 - 2024 — McMap. All rights reserved.