Hi Tom,
Thank you for your interest with Syncfusion products.
Yes, it is possible to send the Key value of the selected item in Autocomplete textbox to controller instead of the Text value. However we haven’t provided default property for sending the Key Value to controller, so you have to get the Key value of the Selected item using OnValueChange event and then pass the value to controller using AJAX post. Define the client side script for OnValueChange event, to fetch the Key value from the Suggestion list and store it to a variable. On Button click event, using AJAX post pass the variable that holds the Key value. Please refer the following code snippet and attached sample.
<code>
[CSHTML]
@Html.Syncfusion().AutocompleteTextBox("Autocomplete").RequestMapper("GetData").DropDown(true).Width(160).ClientSideValueChange("onValueChange")
<input type="button" value="Submit" name="button" onclick="BtnClick(this)
[Script]
<script type="text/javascript">
var
acvalue;
function
onValueChange(sender, args) {
if (args._value == "")
args._value = "Empty";
for(var i=0;i<sender._suggestion.length;i++){
if (args._dataTextItem == sender._suggestion[i].Text)
acvalue = sender._suggestion[i].Value;
}
}
function
BtnClick(args) {
$.ajax({
type: 'POST',
url: '/Tools/ToolsFeatures',
data: { val: acvalue },
success: function (data)
{
}
});
}
</script>
[Controller]
//Post action on button click
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult
ToolsFeatures(string val)
{
var datavalue = val;
return View();
}
//Request mapper for Autocomplete
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult
GetData(string QueryString)
{
List<string>
data = new List<string>();
List<ACsugg>
acdata = new List<ACsugg>();
acdata.Add(new ACsugg("List1", "JQuery
Vs Java Script"));
acdata.Add(new ACsugg("List2", "JQuery"));
acdata.Add(new ACsugg("List3", "Pro
Sync Framework"));
acdata.Add(new ACsugg("List4", "Asp.net
MVC Tutorial"));
acdata.Add(new ACsugg("List5", "Professional
ASP.NET MVC 4 "));
acdata.Add(new ACsugg("List6", "Windows
8 Apps with XAML "));
acdata.Add(new ACsugg("List7", "Syncfusion
jQuery_Succinctly"));
acdata.Add(new ACsugg("List8", "Android
Application Development"));
acdata.Add(new ACsugg("List9", "Basics
in C and C++"));
acdata.Add(new ACsugg("List10", "Dot
net Application development"));
acdata.Add(new ACsugg("List11", "Programming
in C#"));
acdata.Add(new ACsugg("List12", "Advanced
Java"));
var datasource =
acdata.AsQueryable();
return datasource.AutocompleteActionResult();
}
</code>
Kindly let us know if you have further queries.
Regards,
Ezhil S
<ej:Autocomplete ID="multicolumn" runat="server" Width="500px" WatermarkText="Select a order" ShowPopupButton="true" DataTextField="CustomerID" DataUniqueKeyField="OrderID" OnValueSelect="multicolumn_ValueSelect">
</ej:Autocomplete> |
protected void multicolumn_ValueSelect(object sender, Syncfusion.JavaScript.Web.AutocompleteSelectEventArgs e)
{
var val = e.Key;
} |
Thanks a ton for this helpful resource, been into this key-store for a moment and eventually bumped into the PHP redis extension, where Redis is a server that provides a key/value store. It might complete my homework for blogs. Thanks! :)