BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
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.
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
@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 } |
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
Regards,
Kasithangam
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);
} |