How to filter activity when entering in MVC3

I have a list of 2500 classes held in our db. On our website, we ask you to enter your lesson, and I would like it to filter the results as they are entered; like a search on Play.com. Is there a way to do this in MVC3?

Appreciate any help.

+5
source share
2 answers

You can do this using javascript autocomplete.

For example: http://www.pnpguidance.net/post/jQueryAutoCompleteASPNETMVCFramework.aspx

You can capture your data using jQuery Ajax.

+3
source

I would create an action method that returns JSON:

        [HttpGet()]
        public JsonResult Occupations(String searchCriteria)
        {
            String[] occupations = new String[] { "Lawyer", "Carpenter" };
            return Json(occupations.Where(s => s.Contains(searchCriteria))
                                   .ToList(), JsonRequestBehavior.AllowGet);
        }

GET :/? searchCriteria = Carpenter, [ ].

jQuery ajax- . , , li .

ajax json get :

  $.ajax({
            type: 'json',
            url: '/Occupations',
            type: 'GET',
            cache: false,
            data: { searchCriteria: searchCriteria},
            error: function () {

            },
            success: function (result) {               
                alert(result);
            }
        });

, .

0

All Articles