这可能只是我忽略的一个简单的问题,下面的代码从缓存中检索数据,所以当我输入'g'例如我得到3个结果,或者'f'我得到1个结果。< / p>
问题出现在自动完成的页面上,当我输入“g”时,我得到文本框下方的下拉列表,其中3行约为5px高,当我输入“f”时,我得到文本框,但是文本里面没有文字无法看到它点击。
但是,如果我使用硬编码的值,它可以正常工作。
有人能发现我所缺少的东西吗?
控制器:
public ActionResult QuickSearch(string term)
{
var wq = LocationList(term).Select(a => new
{
Value = a.strLocationName
});
return Json(wq, JsonRequestBehavior.AllowGet);
}
private List<DisplayTopOneThousandAutoCompleteWeatherLocations> LocationList(string searchString)
{
var wq = _IGTOTACWL.DisplayTopWeatherLocations()
.Where(a => a.strLocationName.StartsWith(searchString, StringComparison.OrdinalIgnoreCase)).ToList();
return wq.ToList();
}
查看:
@using (Html.BeginForm("Index", "SearchResults", FormMethod.Get, new { @id = "frmWeather" }))
{
<div id="dvWL">
<ul id="ulWeatherSearch">
<li>
<input id="wns" name="q" title="Change location" type="text"/></li>
<li>
<input id="wsb" name="b" type="submit" title="Click to search" value="Weather" /></li>
</ul>
</div>
<input id="hsho" name="o" type="hidden" value="5" />
}
<p class="pIP">Location based on IP Address<br />@ViewBag.IPAddr</p>
<script>
$("#wns").autocomplete({
//source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ],
source: '@Url.Action("QuickSearch","Weather")'
});
</script>
我也试过下面的代码,但没有运气
<script>
$("#wns").autocomplete({
//source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ],
source: '@Url.Action("QuickSearch","Weather")',
dataType: 'json',
parse: function (data) {
var rows = new Array();
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i].strLocationName};
}
return rows;
},
formatItem: function (row, i, n) {
return row.strLocationName;
}
});
</script>