0

I have problem with my ajax-search. When I adding to my model some data, I go to my Index view, where I use my ajax-search. And then I erase text from input and submit form, Index view did not show added data. How to fix that??

It's my SearchController

 public ActionResult Index(string searhcString)
    {
        var competitions = from s in db.Competitions
                           select s;
        if(!String.IsNullOrEmpty(searhcString))
        {
        competitions =competitions.Where(s => s.CompName.ToUpper().Contains(searhcString.ToUpper())
                                       || s.CompName.ToUpper().Contains(searhcString.ToUpper()));
        }

        return View(competitions);
    }

Index View

  @using (Ajax.BeginForm("AjaxSearch", "Competitions",
                      new AjaxOptions
                      {
                          HttpMethod = "GET",
                          InsertionMode = InsertionMode.Replace,
                          UpdateTargetId = "ajaxTable"
                      }))
            {

                <input type="text" name="q" />

            <button type="submit"><img height="10" src="@Url.Content("~/Images/findBtn.png")" /></button>
            }
As Lk
  • 19
  • 1
  • 3

1 Answers1

0

In internet Explorer ajaxs calls are cached by default... may be this is your case.

You can disable this globally this way:

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

Or you can disable it just in this case adding cache: false in your AjaxOptions

Behind scene, this will append a timestamp to each call making it different from previous and that way preventing caching.

If this solves your issue, your could do something similar but sending a checksum of the value of your fields (instead of a timestamp)... this way, the post is only done when the filter/search options indeed changed.

Romias
  • 12,977
  • 7
  • 51
  • 79