c# - MVC autocomplete appending result in sentence -


i'm trying make textbox give suggestions autocompletion of usernames in textbox in mvc. autocompletion part works, can't seem have append username sentence instead of replacing completely!

i'm not comfortable in jquery/javascript, i'm trying as can in c#, think i'm @ roads end that.. i'm using jquery-ui-1.11 autocomplete function after example found here: autocomplete tutorial

this jquery autocomplete script:

    $(".newpostbox").autocomplete({     source: function (request, response) {         var customer = new array();         $.ajax({             async: false,             cache: false,             type: "post",             url: "@(url.action("autocomplete", "home"))",             data: { "term": request.term },             minlength: 2,             success: function (data) {                 (var = 0; < data.length ; i++) {                     customer[i] = { label: data[i].second, id: data[i].first};                 }             }         });         response(customer);     } }); 

i thought being smart using triplet send value/id, have desired "first part of sentence" in data[i].third. close!

i don't know if seeing controller important, i'll post anyways:

[acceptverbs(httpverbs.post)] public jsonresult autocomplete(string term) {      //split string     string[] dividers = { " ", ".", ",", "!", "?", "\n", "\r\n" };     string[] splits = term.split(dividers, stringsplitoptions.removeemptyentries);     int index = splits.length - 1;     //look @ signs     if(index >= 0 && splits[index].length > 1 && splits[index][0] == '@') {         string impoterm = splits[splits.length - 1].substring(1);         int end = term.length - 1;         {             end--;         } while(end >= 0 && term[end] != '@');          string beginning = term.substring(0, end);          //get names db         statictagscontext tagdb = new statictagscontext();         var tags = in tagdb.statictags a.name.contains(impoterm) select a;         list<statictag> taglist = tags.tolist();         var names = new list<triplet>();         //important part guess          for(int = 0; < taglist.count(); i++) {             names.add(new triplet(                 i.tostring(), //first: id                 "@" + taglist[i].name, //second: displayname                 //third: full sentence want in textbox                 beginning + "@" + taglist[i].name));          }         return json(names.tolist(), jsonrequestbehavior.allowget);     }     return json(null); } 

tl;dr: there way separate displayed in dropdown box , put in textbox on selection, jquery autocomplete?


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -