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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Error on AutocompleteFor get key

Thread ID:

Created:

Updated:

Platform:

Replies:

128578 Jan 30,2017 03:30 PM UTC Feb 3,2017 12:33 PM UTC ASP.NET MVC 5
loading
Tags: AutoComplete
Manolo
Asked On January 30, 2017 03:30 PM UTC

Hi,

I've an autocomplete inside a form. I need the ID from the autocomplete text, but it always return null.

I've attach an example, with a dropdownlistfor that the selected item is binding ok, but the autocomplete not returns the ID

Attachment: Autocomplete_eb5bb22e.zip

Arun Palaniyandi [Syncfusion]
Replied On January 31, 2017 10:19 AM UTC

Hi Manolo,   
   
Thanks for contacting Syncfusion Support.   
   
Based on the analysis of your shared code, we found that you had sent the key value (i.e., ID) to the controller. Hence, in your Autocomplete you could not directly send the key value to the code behind. If you want to get the key in controller directly using the Autocomplete ID, then you have to define a hidden input element and set its value on Select event. Refer to the below code sample.    
   
[CSHTML]      
   
@using (Html.BeginForm())   
{   
    <div class="row">   
        <input type="hidden" id="Auto_hidden" name="Auto" />       
        @Html.EJ().AutocompleteFor(x => x.IdCar, newSyncfusion.JavaScript.Models.AutocompleteProperties()   
{   
    DataSource = (IEnumerable<CarsList>)ViewBag.datasource,   
    AutocompleteFields = new AutocompleteFields() { Text = "text", Key = "uniqueKey"}   
}).Width("100%").ClientSideEvents(c => c.Select("onSelect"))      
   
    </div>   
[Script]       
  function onSelect(args) {   
            $("#Auto_hidden").val(args.key);   
        }   
   
[Controller]    
   
[HttpPost]   
        public ActionResult AutocompleteFeatures(CarVM model,string Auto)   
        {   
   
            int Id = Int32.Parse(Auto);      
            return View(model);   
        }   
  
    
   
      
Please let us know if you have any more queries.        
     
Regards,       
Arun P.    


Manolo
Replied On January 31, 2017 11:56 AM UTC

Hi,

I think that Autocompletefor not bind correctly. When I use this control, the key must be binded with the model property automatically. Similar at dropdownlistfor.

Also, if I've set the value for the model property, autocompletefor show the key, not the text.

I've modified the example, and I put also a dropdownlistfor, that it works perfectly, getting ans setting the property model value



Attachment: Autocomplete_8e68ef2.zip

Arun Palaniyandi [Syncfusion]
Replied On February 1, 2017 11:53 AM UTC

Hi Manolo,    
    
Thanks for the update. 
 
As updated earlier, in Autocomplete you could not directly send the key value to the code behind. But in the DropDownList, we are having the text and value property, so that value property can be obtained in controller since that will be stored in the hidden input. 
We have also checked your sample and you have passed the key in the controller but it shows the text only in view not the key. Since this is the behavior of the Autocomplete, we have to manually pass the key to the controller. 
 
If you need not like to pass the key value manually, we suggest you to use the DropDownList with the EnableFilterSearch to behave that will allow you to search like Autocomplete.
 
Please let us know if we have any queries further. 

Regards, 
Arun P. 


Manolo
Replied On February 2, 2017 09:27 AM UTC

Ok, is better use drop down list.

Thanks for all

Arun Palaniyandi [Syncfusion]
Replied On February 3, 2017 12:33 PM UTC

Hi Manolo,     
     
Thanks for the update. 
 
We are glad that our suggestion helped you. 
 
Please let us know if you have any queries in future. 

Regards, 
Arun P. 


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.

Warning Icon 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.Close Icon

;