0

I am using mvcPagedList for paging my index action. Inside index action I return a partial view for ajax requests and whole view for normal requests.

 return Request.IsAjaxRequest()
            ? (ActionResult)PartialView("_index", listPaged)
            : View(listPaged);

But for caching I have problem because it won't detect if the request is ajax or not and instead of returning a partial view I get the whole view or reverse. It depends the first request is ajax or not!

I tried adding VaryByHeader = "X-Requested-With" to OutputCache attribute but no luck. Please guide me. Thanks

mahdi gh
  • 438
  • 1
  • 7
  • 18
  • [This SO question](http://stackoverflow.com/questions/2786690/asp-net-outputcache-varybyparam-and-varybyheader-with-ajax?rq=1) might be handy. – Jason Evans Sep 28 '15 at 07:46
  • I have seen that post already. but I have this code: [OutputCache(CacheProfile = "long", VaryByParam="*", VaryByHeader = "X-Requested-With")] – mahdi gh Sep 28 '15 at 10:47
  • I changed it to this line of code and now it works. but anyone knows how to this with donut caching? [OutputCache(CacheProfile = "long", Location = System.Web.UI.OutputCacheLocation.Server, VaryByParam = "*", VaryByHeader = "X-Requested-With")] – mahdi gh Sep 28 '15 at 12:11

0 Answers0