Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to create dynamic textbox which fetch data from database table using jquery ajax in mvc4,i have done it..here is my code
public JsonResult AutoCompleteTasks(string term)
       {
           var result = (from t in pc.Tasks
                         where t.Name.Contains(term)
                         select new { t.Name }).Distinct();

           return Json(result, JsonRequestBehavior.AllowGet);

       }

and here is ajax,
$("#textarea").autocomplete({

             source: function(request,response) {
                 $.ajax({
                     url: "/Home/AutoCompleteTasks",
                     type: "POST",
                     dataType: "json",
                     data: { term: request.term },
                     success: function (data){
                     {
                         if(data){
                            alert(data.FirstMidName);
                            $("#textarea").val(data.FirstMidName);
                     }
                         response($.map(data, function (item) {
                             return { label: item.Name, value: item.Name };
                         }))
                     }
                 })
             },
             messages: {
                 noResults: "", results: ""
             }
         });


but now i want a textbox which can fetch more than 1 entry separted by commas,like this
task1,task2,task3 in textbox ,how can i do that,,,,,
Posted
Comments
Kumar Prateek 27-Oct-14 9:14am    
So are you looking for instead of
"response($.map(data, function (item) {
return { label: item.Name, value: item.Name };
}))"
Some code to add text boxes with the Name value filled into them?
Mohsin Azam 28-Oct-14 0:02am    
ya...can you?

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