My model is quite complex but basically has a list of fields, each field then has a number of values that can be selected via a drop down. I loop through the fields and try and create a dropdown for each field:
@for (var i = 0; i < Model.Fields.Count; i++) {
var fieldId = "field_" + i.ToString() + "_value_" + j.ToString();
@(Html.Kendo().DropDownList()
.Name(fieldId)
.Value(Model.Fields[i].Values[j])
.Filter("contains")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("TypeAhead", "Document", new { docType = Model.DocType, field = i });
})
.ServerFiltering(true);
})
)
The DataSource just asks the DB what the predefined (drop down) values are for this field:
public ActionResult TypeAhead([DataSourceRequest] DataSourceRequest request, string docType, int field)
{
var predefinedValues = GetPredefinedValuesForField(docType, field, "");
return Json(predefinedValues);
}
This works except that the values for the dropdown are being ADDED to each field -> i.e. field 1 has value1 and value2, field2 has value1, value2 (both from field 1) and then it's own values.
It seems as if I have not bound what comes back from the DataSource in the controller to the field but rather to each field in return?
Any ideas as to what I am doing incorrectly?