Jquery autocomplete with Dynamic input box.?

Posted by Kaps Hasija on Stack Overflow See other posts from Stack Overflow or by Kaps Hasija
Published on 2012-11-20T04:28:52Z Indexed on 2012/11/20 4:59 UTC
Read the original article Hit count: 207

I have done so much R & D for Jquery Auto complete, I found some result but not as much i needed. I am giving you code which are currently i am using .

 <input type="text" value="|a" name="completeMe" id="Subject" />//  This  input  box will  created  by  Dynamic using forloop

// My Jquery Code

     $(function () {
    $("#Subject").autocomplete({
        source: '/Cataloging/Bib/GetSubject',
        minLength: 1,
        select: function (event, ui) {
            // Do something with "ui.item.Id" or "ui.item.Name" or any of the other properties you selected to return from the action
        }
    });
});   

// My Action Method

  public ActionResult GetSubject(string term)
    {
         term = term.Substring(2, term.Length-2);

        return Json(db.BibContents.Where(city => city.Value.StartsWith(term)).Select(city => city.Value), JsonRequestBehavior.AllowGet);
    }

// My code is running with static input but while creating Dynamic I need to use live event but i don't know how can i use Live Event with this code.

NOTE: I am using static value of input "|a" after rendering on action i am removing that first two char to make proper search from database. Thanks

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc-3