I am using kendo autocomplete control in my MVC project(Server side filtering).It list the data correctly. But the problem is when i submit the data to server the autocomplete value id is missing. Because there is no DataValueField attribute in this control. The bellow code is i am using
@(Html.Kendo().AutoComplete()
.Name("Patient")
.Placeholder("Enter Name")
.DataTextField("TextField")
.Filter("contains")
.MinLength(3)
.HtmlAttributes(new { style = "width:100%" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("function", "controller")
.Data("onAdditionalData");
})
.ServerFiltering(true);
})
)
How can i send the value to the server.
Thank you..
Since
AutoCompletehelper doesn't haveDataValueFieldattribute, you need to use other HTML helper as workaround to pass another property value. Suppose your viewmodel has this setup:You can create a hidden field or read-only textbox to store ID property mentioned above inside Razor view:
Then, assign its
valueattribute from client-side script by creating a function which reads item index from autocomplete helper:And finally set the function name bound for
Eventsattribute:By following this setup, the
PatientIDproperty should have ID of the selected value from autocomplete helper when user submitted the form.