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.
Syncfusion Feedback

How to get the selected item ID(KEY) from Autocomplete

Thread ID:

Created:

Updated:

Platform:

Replies:

118911 Apr 22,2015 07:34 PM UTC Jan 10,2017 11:36 AM UTC ASP.NET MVC 13
loading
Tags: AutoComplete
Djamel eddine MACHOUK
Asked On April 22, 2015 07:34 PM UTC

Hello ! 

the scafolding gave me this : 
@Html.DropDownList("Id_Vehicule", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Id_Vehicule, "", new { @class = "text-danger" })

and i replace it with the Syncfusion Autocomplet :
                @Html.EJ().Autocomplete("Id_Vehicule").Width("280").Datasource((IEnumerable<Vehicule>)ViewBag.datasource).AutocompleteFields(f => f.Key("Id_Vehicule").Text("Immatriculation")).HighlightSearch(true).FilterType(FilterOperatorType.Contains).ShowPopupButton(true).EmptyResultText("Véhicule introuvable")

My controller : 
List<Vehicule> v = new List<Vehicule>();
/* ... Adding items code  ...*/
 ViewBag.datasource = v.ToList();

--- in the view Side the Autocomplete works fine.
--- in the controller Side i cant get the Value .

So! how can i get it ? 
Thank you !

Ezhil S [Syncfusion]
Replied On April 23, 2015 10:10 AM UTC

Hi Djamel,
Sorry about the inconvenience caused.

Currently we haven’t provided support to “Return the selected item’s key to controller in Autocomplete” and fix for this issue will available in our upcoming service pack release Volume 1,2015, which is expected to be rolled out at the end of this month. We will let you know once the service pack release has been rolled out. We appreciate your patience until then.

Please let us know if you have any concerns. We will be happy to help you out.
Regards,
Ezhil S

David
Replied On July 22, 2015 08:28 AM UTC

Hi!

we have same issue... some notice? some patch?

My version: 13.1.0.21


Thanks!

Kasithangam C [Syncfusion]
Replied On July 23, 2015 02:11 PM UTC

Hi Djamel,


We have prepared the sample based on get the selected item ID(key) value in controller side and please find the sample under the following location,


Sample: Autocomplete Sample


In the above sample, we have passed the selected item ID to controller in the button click event as shown below,


<code>

<script>

  

    function OnClick(args)

    {

        var val = $("#selectcar").val();

        var obj = $("#selectcar").data("ejAutocomplete");

       var source= obj.option("dataSource");

        for(var i=0;i<source.length;i++)

        {

            if (source[i].text == val) {

                var id = source[i].uniqueKey;

                break;

            }

        }

        $.ajax({

            type: "Post",

            url: "result",

            data: { "id": id },

            success: function (result) {

                alert(result)

            },


        });

            }

</script>


</code>


In the controller page,you can get the id of the item as shown below code,

<code>

public ActionResult result(string id)

        {

            ViewBag.Message = id;

            return PartialView("_Partial1");


        }


</code>

Kindly let us know if you have further queries.

Regards,

Kasithangam


Matthew Shakespeare
Replied On March 24, 2016 12:46 PM UTC

Has "Return the selected item’s key to controller in Autocomplete" become part of default functionality, I'm unable to return the id to my controller.

I'm using the autocomplete control as part of a larger form with multiple autocomplete controls, and i can't see a 'Nice' way of handling it even in sample you posted 

Matthew Shakespeare
Replied On March 24, 2016 12:51 PM UTC

I'm unable to return the id to my controller*

Sasikala Nagarajan [Syncfusion]
Replied On March 26, 2016 05:17 AM UTC

Hi Matthew,

Thanks for contacting Syncfusion support,

We have checked with your requirement. We would like let you know that, we have provided your reported requirement in our latest releases (from 13.4.0.58 Volume 4, 2015 SP1). You can get the key of selected items in form post back by setting the mulitiSelect Mode as “visual mode“. Please refer the below code example,

    @Html.EJ().Autocomplete("selectState").MultiSelectMode(MultiSelectModeTypes.VisualMode).Datasource((IEnumerable<object>)ViewBag.state).AutocompleteFields(f => f.Text("countryName").Key("index"))

[HttpPost]

        public ActionResult GetData(string selectState)

        {

            return View("Index");// from selectState you can get the keys of selected items

        }


If still you are facing any difficluites please provide more information about requirement along with your current EJ version which will help us to provide you the better solution,

Please check with the given solution and let us know if you have further queries,

Regards,

Sasikala Nagarajan

Matthew Shakespeare
Replied On March 26, 2016 01:43 PM UTC

Thank you Sasikala, That resolves my issue

Matthew Shakespeare
Replied On March 27, 2016 04:46 PM UTC

This sorts out my issue of your autocomplete control not returning the selected Item's Id, however by making it a multi-select control to resolve the issue it makes it unusable.
Looking at what you said again i think this might be due to a bad translation "selected item's id" vs "selected items"

I'm currently using the syncfusion.AspNet.Mvc5 nuget package version 13.4.0.63



Kasithangam C [Syncfusion]
Replied On March 28, 2016 01:12 PM UTC

Hi Matthew,

Currently, we don’t have inbuilt functionality for when select the autocompelete item (not multiselect mode) and get the key of selected item in code behind. We have logged defect report for this. A support incident to track the status of this issue has been created under your account. Please log on to our support website to check for further updates.


https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents  


Looking at what you said again i think this might be due to a bad translation "selected item's id" vs "selected items"

Can you please explain clearly, you are going to get the selected item id (key alone) or selected items (key and text) in the code behind?


Please let us know if you have any query.


Regards,

Kasithangam


Matthew Shakespeare
Replied On March 29, 2016 02:50 PM UTC


Can you please explain clearly, you are going to get the selected item id (key alone) or selected items (key and text) in the code behind? 

The id of the selected item 

Kasithangam C [Syncfusion]
Replied On March 30, 2016 06:09 AM UTC

Hi Matthew,

As said in the previous update, we have logged a defect report for the issue “when select the autocompelete item, can’t able to get the key (id) of selected item in code behind”.We will update you once the issue has been fixed. We appreciate your patience until then and also feel free to get back to us if you need any further assistance.


Regards,

Kasithangam


Sean McGurk
Replied On January 9, 2017 11:37 AM UTC

Hi,

Any update on this issue?

I am trying to use the key value for the selected item in my postback (rather than the selected text) and am unable to do so with the Autocomplete control.

Thanks,

Sean


Arun Palaniyandi [Syncfusion]
Replied On January 10, 2017 11:36 AM UTC

 
Hi Sean,   
   
Thanks for contacting Syncfusion support.   
   
In the Autocomplete, we can get the selected item’s key value in controller by 2 ways.   
1.Using select event parameter   
2.Using selectValueByKey property   
   
After getting the key value, we need to send this to code behind by using AJAX. Please find the below code snippet for your reference.   
   
1.Using select event parameter   
   
Cshtml   
  
@Html.EJ().Autocomplete("selectcar").Width("205").Datasource((IEnumerable<CarsList>)ViewBag.datasource)   
.AllowGrouping(false).HighlightSearch(false).AutocompleteFields(f => f.Text("text").Key("uniqueKey")).ClientSideEvents(e => e.Select("onselect"))   
  
<script>   
        function onselect(e) {   
            keyvalue = e.key;   
            $.ajax({   
                type: 'POST',   
                url: '@Url.Action("AutoFeaturesnew""Autocomplete")',   
                data: {   
                    type: keyvalue   
                },   
                success: function (data) {                      
                    alert("key is suucessfully got in controller, Key:"+ data);   
                }   
            });   
    }   
    </script>   
  
Controller   
  
public JsonResult AutoFeaturesnew(string type)   
        {   
   
            return Json(type);   
   
        }   
   
2.Using selectValueByKey property   
   
After selected a text, the selected item’s key value will be maintained in the selectvaluebykey property.   
   
   
Cshtml   
  
<form>   
           @Html.EJ().Autocomplete("selectauto").Width("205").Datasource((IEnumerable<CarsList>)ViewBag.datasource).MultiSelectMode(MultiSelectModeTypes.None).AllowGrouping(false).HighlightSearch(false).AutocompleteFields(e => e.Text("text").Key("uniqueKey"))   
            <br/>   
            <input id="submit" type="submit" value="Submit" />   
        </form>   
<script>   
$('form').submit(function () {   
            var ac = $("#selectauto").ejAutocomplete("instance");   
            $.ajax({   
                url: '/autocomplete/AutocompleteFeaturesnew',   
                data: { val: ac.model.selectValueByKey },   
                type: 'POST',   
                dataType: "json",   
                success: function (data) {   
                    alert("key is suucessfully got in controller through form submit, Key:" + data);   
                }   
   
            });   
   
        });    </script>   
  
Controller   
  
public JsonResult AutocompleteFeaturesnew(string val)   
        {   
            return Json(val);    
        }    


 
 



 
 
  
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

;