neda Derakhshesh neda Derakhshesh - 3 months ago 36x
Javascript Question

implement Autocomplete Search box MVC

I searched a lot to find a plugin or a complete step by step tutorial to implement

search box
something like this

enter image description here

this is my model

public class Question
public virtual int Id { get; set; }
public virtual string Qu { get; set; }
public virtual string Ans { get; set; }
public virtual List<KeyWord> KeyWord { get; set; }

I want to find any related question in database when user enters it's text.


public JsonResult AjaxQuestion()
return Json(db.Questions.ToList());

Appreciate if some one suggest me any way to implement this


You can use Jquery for recovering Data coming from controller (By Ajax), then you can use autocomplete method of Jquery as well...

$(document).ready(function () {
            source: function (request,response) {
                    url: 'controller',
                    dataType: 'json',
                    method: 'POST',
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { field1: item.field1, field2: item.field2, field3: item.field3, field4: item.field4};