I don't know if this is something that is possible or not, but I'm having trouble finding the correct words to search for answers.
Let's say I have a "Location" model with these two properties. City
corresponds to a column in the table with a foreign key to a lookup table of all cities in the local area. CityOther
is a free-text field that allows users to enter any city name they want.
public int? City { get; set; }
public string CityOther { get; set; }
I have a Kendo ComboBox
that's configured something like this:
@(Html.Kendo().ComboBoxFor(m => m.CityOther)
.DataTextField("Text")
.DataValueField("Value")
.Placeholder("Select City")
.Filter(FilterType.Contains)
//.DataSource(d => ...)
)
When I serialize the form, I see two inputs with the names CityOther
and CityOther_input
.
When an existing city from the picklist is chosen, the values look like this:
{ name: 'CityOther' , value: '3' }
{ name: 'CityOther_input', value: 'Springfield' }
When a free-text city (one not from the list) is entered, the values then look like this:
{ name: 'CityOther' , value: 'Orlando' }
{ name: 'CityOther_input', value: 'Orlando' }
I would like to configure it so that:
- a value selected from the existing list would end up in the
City
field (which means I would change it to.ComboBoxFor(m => m.City)
). - a free-text value entered would end up in the
CityOther
field, rather than XYZ_input
.
Is this possible?
Would model binding fail if the value in City
(a nullable int
property) was a string value?