Search code examples
c#jqueryasp.netinternet-explorerwijmo

IE Caching Old Data Returned from Server


I have a Wijmo Tree on a ASP.NET MVC View. The checkstate of each treenode is saved in my database. When the tree is loaded, each node is checked or unchecked according to the data returned. When the nodeCheckChanged on the tree is called, I use ajax to call an action on my controller which successfully changes my data.

The problem arises when I reload the treeview. The data has saved in the database, but the browser does not get the latest data from the server.

I only get the problem in IE all versions. Firefox and Chrome work every time.

I have looked at pages like this from DotNetPerls,this from Microsoft, and tried option four on this stackoverflow answer.

The only way I have found to get the latest data in IE is the set to true the option Developer Tools -> Cache -> Always Refresh from Server.

What do I need to do so IE reloads my data like other browsers?

Thank-you all for taking the time to read this question!

Edit

The data for my tree comes from a collection on my model. This collection is populated by an action.

My action:

public ActionResult List(AssignedFolderListModel model)
{
    //Using EntityFramework
    model.TopLevelFolders = db.Folders;
    return PartialView(model);
}

My model:

public class AssignedFolderListModel
{
    public string UserId { get; set; }
    public IEnumerable<Folder> TopLevelFolders { get; set; }
    public Guid[] AssignedFolderIds { get; set; }
}

Answer

I needed to add "cache: false" to my $.ajax call. The $.ajax call is being made to the same url each time. eg. "AssignedFolder/List?UserId=12345". IE was not making the call again, but rather returning a cached result.

Now IE is forced to return the latest data each time.


Solution

  • IE caches all gets - you need to do something to the request to trick IE not to cache it. With a jQuery.ajax call, you can set "cache: false" on the call (which just adds a random timestamp to the requested URL) - Look for a configuration option on that tree about doing that, or a hook where you can manipulate the URL used to reload the data from the server (and add your own timestamp to the requested URL).