0

I generate html like this in javascript as you can see theres an a tag in html

when I click first time in link it hit the action, but sometimes (can say 90% of cases) second click doesnt hit the action unless I clear the firefox or chrome cache what's going here? and how can I solve this problem?

$.each(response, function (index, item) {
                            htmlcontent = "<div class=''>" +
                                "<a target='_blank' href='/Stat/" + item.Code + "/" + item.RId + "'>" +
                                "<img class=''  src='/Images/" + item.ImageId + "'/>" +
                                "</a>" +
                                "</div>";
                            $('.div_SecondCol').eq(index).html(htmlcontent);
                        });

and this is action

 // GET: Stat/{code}/{RId}
public ActionResult AdsStat(string Code, int? RId)
        {

            try
            {
                #region Load Data
                  //some code
                #endregion
                #region Insert Data
                  //some code
                #endregion

                return RedirectPermanent(externalUrl);

            }
            catch (Exception e)
            {

            }
        }

when I add a random number at the end of href it works! but I need to know what's going here?

var randnum = Math.floor((Math.random() * 1000) + 1);
"<a target='_blank' href='/Stat/" + item.Code + "/" + item.RId + "?rnum=" + randnum + "'>" +

1 Answers1

0

I think its because HTTP Permanent Redirects 301 is cached by default. So browser opens cached page with identical URL, instead of making trip on server. Thats why its working, when you add random url parameter.

More about caching on Link

If you want to disable caching in general or disable caching on specific action. I would suggest to try solution from Prevent Caching in ASP.NET MVC or ASP.NET MVC how to disable automatic caching option

Kamil Folwarczny
  • 581
  • 1
  • 3
  • 13