Click here to Skip to main content
15,398,850 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in view:
<script src=""></script>
@using (Html.BeginForm()) {

       <button type="submit" value="Search" id="btnSearch" name="Command">Search</button>
<script type="text/javascript">

$(document).ready(function () {

            source: "/Search/Create",
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {

in controller:
public ActionResult Create(string Search)

var res = from m in db.Countries
                      where m.Countrys.Contains(Search)
                      select m;
            return Json(res, JsonRequestBehavior.AllowGet);

but it not working can anyone tell me what is problem i am new to jquery and json

1 solution

View page



$(document).ready(function () {
source: function(request,response) {
url: "/Home/AutoCompleteCountry",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Country, value: item.Country };

messages: {
noResults: "", results: ""

here is the code of AutoCompleteCountry method that will accept a parameter and return the matching JSON data.

public JsonResult AutoCompleteCountry(string term)
var result = (from r in db.Customers
where r.Country.ToLower().Contains(term.ToLower())
select new { r.Country }).Distinct();
return Json(result, JsonRequestBehavior.AllowGet);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900