Hi all,
Im using Autocomplete in my .js
i've added some properties to the source (like p which is a Class array - myClass[])
i want to be able to return this class as well as the
realValue to the modelAction (using MVC)
but the class comes empty.
please help :)
Class example
- public class Service
- {
- public string name { get; set; }
- public ServiceProblem[] problems { get; set; }
- }
my .cshtml:
- @Html.AutocompleteFor(Url.Action("AutoCompleteServiceProviders", "Create"), true, "ex. Shower", c => c.name, c => c.problems)
my .js file
- $(element).autocomplete({
- minLength: 2,
- source: function (request, response) {
- $.ajax({
- url: requestUrl,
- dataType: "json",
- data: { query: request.term },
- success: function (data) {
- response($.map(data, function (item) {
- return {
- label: item.Label,
- value: item.Label,
- p: item.p,
- realValue: item.Value
- };
- }));
- },
- });
- },
- select: function (event, ui) {
- var hiddenFieldName = $(this).attr('data-value-name'); // => name
- $('#'+hiddenFieldName).val(ui.item.realValue);
- $('#problems').val(ui.item.p);
- }
- });