私のMVC4アプリケーションには、世界中のすべての都市のデータベースに接続するオートコンプリートがあります(そのため、かなり大きいと想像できます)。PCでは問題なく動作しますが、スマートフォンでサイトにアクセスすると、読み込みに3秒ほどかかり、パフォーマンスが非常に遅くなります。AjaxまたはJSONを使用すると高速になりますか?コードは次のとおりです(私はpluralsightチュートリアルのコードを使用しています):
ビューの一部+Javascript
<!--Searching through all the hotel locations -->
<p>Hotel Location (City): @Html.TextBoxFor(x => x.booking_instance.Location,
new { data_autocomplete = @Url.Action("QuickSearch", "Booking") })</p>
<script type="text/javascript">
$(document).ready(function () {
$(":input[data-autocomplete]").each(function () {
$(this).autocomplete({ source: $(this).attr("data-autocomplete") });
});
});
</script>
コントローラ
// this is my database of cities.
TE_TSQL1_HBOSDataContext _db = new TE_TSQL1_HBOSDataContext();
public ActionResult QuickSearch(string term)
{
var cities = _db.Cities
.Where (r => r.CityName.Contains(term))
.Select(r => new { label = (r.CityName + ", " + r.CountryName) });
return Json(cities, JsonRequestBehavior.AllowGet);
}