c# - Update filter on every stroke -
i'm using c# in mvc 5. trying update search results upon every key stroke. i've wrote think logical. in view wrote ajax communicate post controller.
@using (html.beginform("index", "directory", formmethod.post)) { <p> search employee: <input type="text" name="username" onkeyup="filterterm(this.value);" /> </p> } <script> function filterterm(value) { $.ajax({ type: "post", url: '@url.action("index","directory")', data: json.stringify({ username: value }), contenttype: "application/json; charset=utf-8", datatype: "json", success: function (msg) { $("#sendercontent").html(msg.tostring); }, error: function () { alert("not connected!"); } }); } </script> and controller:
[httppost] public actionresult index(string username) { /**********establish connection********/ directoryentry dir = createdirectoryentry(); directorysearcher search = new directorysearcher(dir); /****refer class constructor****/ /********create list store results in***************/ list<aduser> users = new list<aduser>(); string displayname = "", samaccountname = "", mail service = "", description = "", section = "", telephonenumber = "", fax = ""; /*******filter parameters************/ search.filter = "(&((&(objectcategory=person)(objectclass=user)))(anr=" + username + "* ))"; searchresultcollection searchresult = search.findall(); search.propertiestoload.add("displayname"); search.propertiestoload.add("samaccountname"); search.propertiestoload.add("mail"); search.propertiestoload.add("description"); search.propertiestoload.add("telephonenumber"); search.propertiestoload.add("fax"); search.propertiestoload.add("department"); /*****************filtering , populating list****************/ if (searchresult != null) { foreach (searchresult iresult in searchresult) { aduser userattributes = new aduser("", "", "", "", "", "", ""); foreach (string propertyname in iresult.properties.propertynames) { foreach (object key in iresult.getdirectoryentry().properties[propertyname]) { seek { switch (propertyname.toupper()) { case "displayname": displayname = key.tostring(); userattributes.name = displayname; break; case "samaccountname": samaccountname = key.tostring(); userattributes.domainusername = samaccountname; break; case "mail": mail service = key.tostring(); userattributes.emailaddress = mail; break; case "description": description = key.tostring(); userattributes.jobdescription = description; break; case "telephonenumber": telephonenumber = key.tostring(); userattributes.telephonenumber = telephonenumber; break; case "fax": fax = key.tostring(); userattributes.faxnumber = fax; break; case "department": section = key.tostring(); userattributes.department = department; break; } } grab { } } } users.add(userattributes); } homecoming view(users); } homecoming view(); } i've been monitoring happens in fiddler , doesn't flag issue, ajax error message keeps prompting. i've tested value before beingness passed ajax, , reading value correctly. wondering why i'm getting prompted error. in ajax?
c# jquery ajax post
No comments:
Post a Comment