MVC - Outputcache - post params - VaryByParam no effect

1k views Asked by At

I have a MVC page being hit by a normal form post with 2 post parameters.

SupplierId and Repayment.

Before adding the form I used Outputcache on the action like:

[OutputCache(Duration = 86400, VaryByCustom = "pageurl")]
public override ActionResult Load(int ControlId)
{

Everything worked when the url changed.

Now I want it to vary by the post parameters aswell, so I changed it to:

[OutputCache(Duration = 86400, VaryByCustom = "pageurl", VaryByParam = "SupplierId;Repayment")]
public override ActionResult Load(int ControlId)
{

This does not work. It does not cache separat result for different post params. If I request the same url with different post params I keep getting the initial cached result. The break point in Visual Studio is not being hit either.

Can someone tell me what I might be doing wrong?

1

There are 1 answers

0
Rebecca On

VaryByParam relates to the parameters passed into this method. The only param you have is int ControlId.

To VaryByParam = "SupplierId;Repayment" you would need:

[OutputCache(Duration = 86400, VaryByCustom = "pageurl", VaryByParam = "SupplierId;Repayment")]
public override ActionResult Load(int SupplierId, int Repayment)
{
}