我的ajax搜索有问题。当我在我的模型中添加一些数据时,我会转到索引视图,在那里我使用ajax-搜索。然后I从输入和提交表单中删除文本,索引视图没有显示添加的数据。如何修复??
这是我的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>
}发布于 2013-07-05 22:48:17
在中,默认情况下会缓存ajaxs调用..。也许这就是你的案子。
您可以通过这样的方式全局禁用此功能:
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});或者只在本例中禁用它,在您的cache: false中添加AjaxOptions
在场景后面,这将在每个调用中附加一个时间戳,使其与以前的不同,从而防止缓存。
如果这解决了您的问题,您可以执行类似的操作,但是发送字段值的校验和(而不是时间戳).这样,只有当筛选/搜索选项确实发生变化时,才会完成post。
https://stackoverflow.com/questions/17497483
复制相似问题