I uploaded a repro project demonstrating the issue I'm having here: http://www.mediafire.com/download/s1ba31xy83naa8c/NullableComboboxInGrid.zip
Have a grid for a model with a nullable int (representing a FK relationship)
Editor template for the nullable FK property is:
Grid is pretty basic:
When editing, everything works fine. But when adding, the FkId is not bound to the combobox and the value is not update when the combobox is changed. You can see that it is not updated in the grid and it is not posted back to the controller.
When using the exact same setup with a non-nullable property it works as expected. I have a demo of both in the uploaded project.
Have a grid for a model with a nullable int (representing a FK relationship)
public
class
NullableFkModel
{
[ScaffoldColumn(
false
)]
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
[UIHint(
"Fk"
)]
public
int
? FkId {
get
;
set
; }
}
@model
int
?
@(Html.Kendo()
.ComboBoxFor(m => m)
.DataValueField(
"Value"
)
.DataTextField(
"Text"
)
.BindTo(
new
[] {
new
SelectListItem() { Text =
"Joe Blow"
, Value =
"1"
},
new
SelectListItem() { Text =
"Jane Doe"
, Value =
"2"
},
new
SelectListItem() { Text =
"Batman"
, Value =
"3"
}})
.Filter(FilterType.Contains))
Grid is pretty basic:
@(Html.Kendo()
.Grid<NullableFkModel>()
.Name(
"Grid"
)
.Columns(columns =>
{
columns.Bound(item => item.Name);
columns.Bound(item => item.FkId);
columns.Command(command => command.Edit());
})
.DataSource(ds => ds.Ajax()
.Model(model => model.Id(m => m.Id))
.Read(read => read.Action(
"Nullable_Read"
,
"Demo"
))
.Create(create => create.Action(
"Nullable_Create"
,
"Demo"
))
.Update(update => update.Action(
"Nullable_Update"
,
"Demo"
))
)
.ToolBar(commands => commands.Create())
.Editable(edit => edit.Mode(GridEditMode.PopUp)))
When editing, everything works fine. But when adding, the FkId is not bound to the combobox and the value is not update when the combobox is changed. You can see that it is not updated in the grid and it is not posted back to the controller.
When using the exact same setup with a non-nullable property it works as expected. I have a demo of both in the uploaded project.