Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

autocomplete issue

AMNKumariAMNKumari USMember ✭✭✭
edited July 2020 in General

i have a search textbox. and user enter text start with this "[" i have to load text from sql table. i am using below functions

<input id='txtMyText' type='text' onkeypress='getOnChangeText()'/>

My table text have without [ ] this. so i have to remove them before start search.

function getOnChangeText() { 
    var str = $("#txtMyText").val();  
    var strText  = str.replace("[", "");   
    $.ajax({
        url: '../../Page/TextSearch',
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify({ translateText: strText }), 
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
              $("#txtMyText").autocomplete({
                  source: data
        });   
        }
    });    
}
    [HttpPost]
        public ActionResult TextSearch(string translateText)
        {
            var dbContext = new MydatabaseDbEntities();
            var names = dbContext.FreeTexts.Where(p => p.TextString.Contains(translateText)).Select(p => p.TextString).ToList();
            return Json(names, JsonRequestBehavior.AllowGet);
        }

when user type this [ i have to load my text. but my search is not working because my text box have this " [ "

this is working

this is not working

Best Answer

  • AMNKumariAMNKumari USMember ✭✭✭
    Accepted Answer

    fixed it my self

      [HttpPost]
            public ActionResult TextSearch(string translateText)
            {
                var dbContext = new MydatabaseDbEntities();
                var names = dbContext.FreeTexts.Where(p => p.TextString.Contains(translateText)).Select(p => "[" + p.TextString+ "]").ToList();
                return Json(names, JsonRequestBehavior.AllowGet);
            }
    

Answers

  • AMNKumariAMNKumari USMember ✭✭✭
    Accepted Answer

    fixed it my self

      [HttpPost]
            public ActionResult TextSearch(string translateText)
            {
                var dbContext = new MydatabaseDbEntities();
                var names = dbContext.FreeTexts.Where(p => p.TextString.Contains(translateText)).Select(p => "[" + p.TextString+ "]").ToList();
                return Json(names, JsonRequestBehavior.AllowGet);
            }
    
Sign In or Register to comment.