2013-07-05 258 views
0

我有我的ajax搜索問題。當我向模型中添加一些數據時,我會轉到我的索引視圖,在那裏使用我的ajax搜索。然後我從輸入和提交表格中刪除文本,索引視圖沒有顯示添加的數據。如何解決這個問題 ??空輸入沒有返回附加值

這是我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> 
      } 

回答

0

在Internet Explorer ajaxs呼叫默認緩存......可能這是你的情況。

可以禁用這個全球這樣:

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

或者你也可以在這種情況下,您的AjaxOptions

幕後加入cache: false禁用它,這將追加時間戳給每個呼叫使它與以前不同,這種方式防止緩存。

如果這解決了你的問題,你可以做類似的事情,但發送你的字段的值(而不是時間戳)的校驗和......這樣,只有當過濾器/搜索選項確實改變。

+0

ow,我找到解決辦法,我只是改變**'AjaxOption HttpMetod從GET到POST ** –