Commits

Anonymous committed 9f60563

..Working on making it able to return custom data.
..We also need to still port over the example of usage for SENDING custom data to the server.

  • Participants
  • Parent commits a7e12fa
  • Branches custom_tooltip

Comments (0)

Files changed (4)

TestWebsite/Controllers/HomeController.cs

             return View();
         }
 
-        public ActionResult Search(string term, string controlId)
-        {
-            var m = new int[1,2,3];
-
-            var MyData = new[] { new { id = "001000101", label = "my label - 001000101" }, new { id = "001010020", label = "blah = 001010020"} };
-
-            if (string.IsNullOrEmpty(term))
-            {
-                return Json(MyData);
-            }
-            var iltered = (from str in MyData where str.label.Contains(term) select str).ToList();
-
-            return Json(iltered);
-        }
-
         public ActionResult About()
         {
             return View();

TestWebsite/Controllers/hAutoCompleteController.cs

         public ActionResult Search(HAutoCompletePostData postData)
         {
 
-            var fakedDatabaseData = new List<HAutoCompleteReturnData>
+            var fakedDatabaseData = new List<HAutoCompleteReturnData.ListItem>
                                         {
-                                            new HAutoCompleteReturnData() {id = "01", label = "homer simpson"},
-                                            new HAutoCompleteReturnData() {id = "02", label = "arnold swatzenegger"},
-                                            new HAutoCompleteReturnData() {id = "03", label = "robo cop"},
-                                            new HAutoCompleteReturnData() {id = "04", label = "karate kid"},
-                                            new HAutoCompleteReturnData() {id = "05", label = "rambo"},
-                                            new HAutoCompleteReturnData() {id = "06", label = "universal soldier"}
+                                            new HAutoCompleteReturnData.ListItem() {id = "01", label = "homer simpson"},
+                                            new HAutoCompleteReturnData.ListItem() {id = "02", label = "arnold swatzenegger"},
+                                            new HAutoCompleteReturnData.ListItem() {id = "03", label = "robo cop"},
+                                            new HAutoCompleteReturnData.ListItem() {id = "04", label = "karate kid"},
+                                            new HAutoCompleteReturnData.ListItem() {id = "05", label = "rambo"},
+                                            new HAutoCompleteReturnData.ListItem() {id = "06", label = "universal soldier"}
                                         };
 
+            var returnModel = new HAutoCompleteReturnData();
+
 
             //Return everything if empty search term is detected
             if (string.IsNullOrEmpty(postData.term))
             {
-                return Json(fakedDatabaseData);
+                returnModel.resultList = fakedDatabaseData;
+            } else
+            {
+                returnModel.resultList =
+                    (from str in fakedDatabaseData where str.label.Contains(postData.term) select str).ToList();
             }
-
-            var filtered = (from str in fakedDatabaseData where str.label.Contains(postData.term) select str).ToList();
-            return Json(filtered);
+            
+            
+            // ReSharper disable Asp.NotResolved
+            return View(returnModel);
+            // ReSharper restore Asp.NotResolved
         }
     }
 }

TestWebsite/Models/hAutoComplete/HAutoCompleteReturnData.cs

-namespace TestWebsite.Models.hAutoComplete
+using System.Collections.Generic;
+
+namespace TestWebsite.Models.hAutoComplete
 {
     public class HAutoCompleteReturnData
     {
-        public string id { get; set; }
-        public string label { get; set; }
+        public IEnumerable<ListItem> resultList { get; set; }
+
+        public class ListItem
+        {
+            public string id { get; set; }
+            public string label { get; set; }
+        }
     }
 }

TestWebsite/Scripts/hAutoComplete/hAutoComplete.js

                 url: options.source,
                 growl: true,
                 single: false,
+                cache: true,
                 surpressIfError: surpressErrors,
                 dataFunc: function() {
                     var dataPackage = {
                     return dataPackage;
                 },
                 success: function(json) {
-                    response(json);
+                    response(json.resultList);
                 }
             });
         };