As discussed in the comments, it's a caching issue. Adding
cache:false
to the AJAX call will work around the problem.
$.ajax({
type: "GET",
url: "/CreateApplicationFromSearch/CreateApplicationFromSearch",
contentType: "application/json; charset=utf-8",
cache: false,
...
jQuery.ajax() | jQuery API Documentation[
^]
Other options would include using a custom attribute on the action to disable browser caching:
c# - Prevent Caching in ASP.NET MVC for specific actions using an attribute - Stack Overflow[
^]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
...
[HttpGet]
[NoCache]
[AllowAnonymous]
public ActionResult CreateApplicationFromSearch(...)
Or changing the action to use a
POST
request, which will never be cached.
[HttpPost]
[AllowAnonymous]
public ActionResult CreateApplicationFromSearch(...)
$.ajax({
type: "POST",
url: "/CreateApplicationFromSearch/CreateApplicationFromSearch",
contentType: "application/json; charset=utf-8",
...
Some HTTP methods MUST cause a cache to invalidate an entity. ... These methods are: