Friday, September 11, 2015

jQuery, Entity Framework and ASP.NET MVC

<input type="text" id="mpvalue" name="mpvalue" />

<script type="text/javascript">
    $(document).ready(function () {

        $('#mpvalue').autocomplete({
            source: '@Url.Action("GetMP")'
        });

    })


</script>

public ActionResult Index()
     {
        
           return View();
     }

public ActionResult GetMP(string term)
      {
         var result = from r in _db.GetMPDetails()
                         where r.Name.ToLower().Contains(term)
                         select r.Name;          
            return Json(result, JsonRequestBehavior.AllowGet);
        }