We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to

Thread ID:

Created:

Updated:

Platform:

Replies:

128099 Jan 2,2017 08:30 AM Jan 4,2017 12:37 AM ASP.NET MVC 4
loading
Tags: AutoComplete
Cholet
Asked On January 2, 2017 08:30 AM

I have an input box 'CP' and an autocomplete 'TOWN'
I have an ActionResult foundTownWithCP(string CP, string Town)

How I can set the datasource of the autocomplete 'TOWN' with the value of the inputbox 'CP' and the value of my autocomplete 'TOWN' ?

thanks,

Selvamani Sankarappan [Syncfusion]
Replied On January 3, 2017 04:32 AM

Hi Cholet,   
  
Thanks for using Syncfusion products.   
  
You can set the input value to the autocomplete dataSource by converting the string data to the JSON object. Refer to the following code example:  
 
[cs] 
public JsonResult text(string data) 
        { 
            var userData = new UserData() { text = data }; 
            UserData[] arr = new UserData[] { userData }; 
            string json_data = JsonConvert.SerializeObject(arr); 
            return Json(json_data, JsonRequestBehavior.AllowGet); 
        } 
 
We have added the input value to the autocomplete dataSource by using the button click event.   
Refer to the following code example:   
 
[script] 
function onclick() { 
        var data = $("#input").val(); 
        $.ajax({ 
            url: "/Home/text", 
 
            data: { data: data }, 
 
            type: 'POST', 
 
            dataType: "json", 
 
            success: function (result) { 
                var data1 = JSON.parse(result); 
                var obj = $('#selectcar').data("ejAutocomplete"); 
                obj.model.dataSource.push(data1[0]); 
                obj.option("dataSource", obj.model.dataSource); 
                obj.option("fields", { text: "text" }); 
            } 
        }); 
    } 
 
Refer to the following sample: 
 
If you still face any difficulties, kindly get back to us. We will be happy to help you. 
Regards, 
Selvamani S. 
  


Cholet
Replied On January 3, 2017 05:32 AM

Thanks, but in your example, I must to click on a button to see the autocomplete.
It's not possible automatically ?

best regards,

Cholet
Replied On January 3, 2017 08:16 AM

I understand, it's work fine.
thanks

Preethi Nesakkan Gnanadurai [Syncfusion]
Replied On January 4, 2017 12:37 AM

Hi  Cholet, 
  
Most Welcome. 
  
Please let us know if you need further assitance on this. 
  
Regards,  
Preethi 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;