I am using a Kendo UI DropDownList to allow users to choose a State on 2 different pages. On page A, the StateId property being edited is on the core model object. On page B, the StateId property is 1 object deeper. The 2 pages are for editing TaxRules and Customers, with the Model classes as follows:
public class TaxRuleModel {
public int StateId {get; set;}
}
public class CustomerModel {
public AddressModel Address {get; set;}
}
public class AddressModel {
public int StateId {get; set;}
}
Both pages create a drop down list as follows, with the selector being the only difference:
input[name='StateId'] vs input[name='Address.StateId']
$(selector).kendoDropDownList({
dataTextField: "DisplayText",
dataValueField: "Value",
optionLabel: "Select One",
dataSource: {
type: "json",
error: handleKendoGridCrudError,
transport: { read: {Url: url, dataType: "json"}},
schema: {
model:
{
fields:
{
Value: { type: "number" },
DisplayText: { type: "string" }
}
}
}
}
});
The URL returns a JSON list of :
public class StateModel
{
public int Value {get; set;}
public String DisplayText {get; set;}
}
The MVC methods to handle saving the models on each page have the following signatures:
public ActionResult Edit([DataSourceRequest] DataSourceRequest dataSourceRequest, TaxRule model);
public ActionResult Edit([DataSourceRequest] DataSourceRequest dataSourceRequest, Customer model);
The drop down list appears as expected on both pages. On page A, when editing the TaxRule objects, the Form key with the value of the StateId is "StateId" as expected. This allows the StateId value to automatically bind to the TaxRule model as expected and be available in the action method on the model instance. However, on page B, when editing the Customer object, the Form has 2 keys related to the StateId: "Address.StateId.Value" and "Address.StateId.DisplayText". Because of this, the StateId never binds to the Customer.Address.StateId property of the model in MVC. Clearly the problem is that Kendo is attaching the entire lookup list State object to Address.StateId. But I can't figure out why it would behave differently in these 2 different cases. My schema model for the TaxRule and Customer objects look like this:
model: // TaxRule
{
id: "Id",
fields:
{
Id: { defaultValue: 0 },
StateId: {}
}
}
model: // Customer
{
id: "Id",
fields:
{
Id: { type: "number", defaultValue: 0 },
Address:
{
defaultValue: {},
Id: { type: "number", defaultValue: 0 },
StateId: {}
}
}
}
How can I get this to work properly?
public class TaxRuleModel {
public int StateId {get; set;}
}
public class CustomerModel {
public AddressModel Address {get; set;}
}
public class AddressModel {
public int StateId {get; set;}
}
Both pages create a drop down list as follows, with the selector being the only difference:
input[name='StateId'] vs input[name='Address.StateId']
$(selector).kendoDropDownList({
dataTextField: "DisplayText",
dataValueField: "Value",
optionLabel: "Select One",
dataSource: {
type: "json",
error: handleKendoGridCrudError,
transport: { read: {Url: url, dataType: "json"}},
schema: {
model:
{
fields:
{
Value: { type: "number" },
DisplayText: { type: "string" }
}
}
}
}
});
The URL returns a JSON list of :
public class StateModel
{
public int Value {get; set;}
public String DisplayText {get; set;}
}
The MVC methods to handle saving the models on each page have the following signatures:
public ActionResult Edit([DataSourceRequest] DataSourceRequest dataSourceRequest, TaxRule model);
public ActionResult Edit([DataSourceRequest] DataSourceRequest dataSourceRequest, Customer model);
The drop down list appears as expected on both pages. On page A, when editing the TaxRule objects, the Form key with the value of the StateId is "StateId" as expected. This allows the StateId value to automatically bind to the TaxRule model as expected and be available in the action method on the model instance. However, on page B, when editing the Customer object, the Form has 2 keys related to the StateId: "Address.StateId.Value" and "Address.StateId.DisplayText". Because of this, the StateId never binds to the Customer.Address.StateId property of the model in MVC. Clearly the problem is that Kendo is attaching the entire lookup list State object to Address.StateId. But I can't figure out why it would behave differently in these 2 different cases. My schema model for the TaxRule and Customer objects look like this:
model: // TaxRule
{
id: "Id",
fields:
{
Id: { defaultValue: 0 },
StateId: {}
}
}
model: // Customer
{
id: "Id",
fields:
{
Id: { type: "number", defaultValue: 0 },
Address:
{
defaultValue: {},
Id: { type: "number", defaultValue: 0 },
StateId: {}
}
}
}
How can I get this to work properly?