0

我的 ajax 搜索有问题。当我向我的模型添加一些数据时,我会转到我的索引视图,在那里我使用我的 ajax-search。然后 我从输入中删除文本并提交表单,索引视图没有显示添加的数据。如何解决

这是我的 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);
    }

索引视图

  @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>
            }
4

1 回答 1

0

在 Internet Explorer 中,默认情况下会缓存 ajaxs 调用......可能就是您的情况。

您可以通过以下方式全局禁用此功能:

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

或者您可以在这种情况下禁用它,添加cache: false您的AjaxOptions

在幕后,这将为每个调用附加一个时间戳,使其与以前的调用不同,从而防止缓存。

如果这解决了您的问题,您可以做类似的事情,但发送字段值的校验和(而不是时间戳)......这样,只有在过滤器/搜索选项确实发生变化时才会发布帖子。

于 2013-07-05T22:48:17.130 回答