Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <link href="~/Content/css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
  2. <script src="~/Scripts/jquery-1.10.2.js"></script>
  3. <script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script>
  4.  
  5. <script type="text/javascript">
  6. $(function () {
  7. $("#txtSearch").autocomplete({
  8. source: '@Url.Action("GetTitle")'
  9. });
  10. });
  11.  
  12. [HttpPost]
  13. public ActionResult Index(string Search)
  14. {
  15. List<Legislation> objLegis = new List<Legislation>();
  16. if (!string.IsNullOrEmpty(Search))
  17. {
  18. objLegis = db.Legislations.Where(x => x.TITLE.StartsWith(Search) || x.NUMBER.StartsWith(Search)).ToList().Take(10).ToList<Legislation>();
  19. ModelState.Clear();
  20. }
  21. else
  22. {
  23. objLegis = db.Legislations.ToList().Take(10).ToList<Legislation>();
  24. }
  25. return View(objLegis);
  26. }
  27.  
  28. public JsonResult GetTitle(string term)
  29. {
  30. elawdb_liveEntities db = new elawdb_liveEntities();
  31. List<string> objLegis;
  32. objLegis = db.Legislations.Where(x => x.TITLE.StartsWith(term))
  33. .Select(y => y.TITLE).ToList();
  34.  
  35. return Json(objLegis, JsonRequestBehavior.AllowGet);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement