This is a migrated thread and some comments may be shown as answers.

How to bind Id of selected value back to the controller?

1 Answer 56 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
King Wilder
Top achievements
Rank 2
King Wilder asked on 15 Mar 2013, 06:49 PM
Maybe I'm going about this the wrong way but the model populating the AutoComplete has an Id and a Name.  I display the Name but when the form is submitted I need to return the Id since it will bind to the property on the model.

Presently the AutoComplete is populated correctly when I start entering data, but when I submit the form, the widget has the red border meaning that it's not returning the int property type but the string type.

These are two of the AutoComplete properties on my model that I need to bind to:
[DisplayName("Vendor")]
public int? VendorId { get; set; }
 
[DisplayName("Category")]
public int CategoryId { get; set; }
Here is my Vendor AutoComplete widget:
@(Html.Kendo().AutoComplete().Name("Expense.VendorId")
    .DataTextField("VendorName")
    .Filter(FilterType.StartsWith)
    .Placeholder("Type in a Vendor...")
    .DataSource(dataSource =>
    {
        dataSource.Read(read => read.Action("_GetVendors", "Expense"));
    })
    )
Bottom line: I need to bind the Id of the selected value back to the controller, so I need to know how to return the Id from the AutoComplete widget and include it with the response.

Any help on this is appreciated.

Thanks.

1 Answer, 1 is accepted

Sort by
0
King Wilder
Top achievements
Rank 2
answered on 15 Mar 2013, 07:20 PM
Nevermind.  I read one of the posts in the Web Forum with the same issue and it suggested to use the ComboBox instead.

It now does what I need.
Tags
AutoComplete
Asked by
King Wilder
Top achievements
Rank 2
Answers by
King Wilder
Top achievements
Rank 2
Share this question
or