空输入未返回添加值

时间:2013-07-05 22:12:38

标签: asp.net-mvc-4 asp.net-mvc-ajax

我的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>
            }

1 个答案:

答案 0 :(得分:0)

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

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

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

或者您可以在cache: false

添加AjaxOptions的情况下禁用它

在场景后面,这会为每个调用添加一个时间戳,使其与之前的调用不同,从而防止缓存。

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