Привет есть код. Я пытаюсь задать источник для UI auticomplete
public ActionResult Index(string term)
{
List<dynamic> lst;
using (System.IO.StreamReader reader = new System.IO.StreamReader(Url.Content(Server.MapPath(@"Data/data.json"))))
{
string json = reader.ReadToEnd();
lst = JsonConvert.DeserializeObject<List<dynamic>>(json);
}
var Items=lst.Where(item=>item.IndexOf(term,StringComparison.InvariantCultureIgnoreCase) >= 0);
return Json(Items, JsonRequestBehavior.AllowGet);
}
Но не выходит!! Пишет что нет определения для IndexOf
UPD!!!
Решил поробывать вот так
public JsonResult Search(string term)
{
List<dataJson> lst = new List<dataJson>();
lst.Add(new dataJson { Id = 1, City = "Москва" });
lst.Add(new dataJson { Id = 2, City = "Мокварич" });
lst.Add(new dataJson { Id = 3, City = "Могилево" });
lst.Add(new dataJson { Id = 4, City = "Москвцц" });
lst.Add(new dataJson { Id = 5, City = "Москцвцва" });
lst.Add(new dataJson { Id = 6, City = "Москвцвцва" });
var CityName = (from item in lst where item.City.Contains(term) select new { item.City });
return Json(CityName, JsonRequestBehavior.AllowGet);
}
Все вроде ОК и если начать вводить то возвращает и открывается список но он пустой хотя подсказка пишет что найдено 4 соответствий. Не пойму почему список пустой
item
у Вас всегда строка?$(function () { $("#list").autocomplete({ source: @Url.Action("Index") //minLength: 0 });//.focus(function () { //$(this).autocomplete("search"); // }); });