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

Nullable property in grid doesn't update (when bound to combobox)

4 Answers 382 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 14 Jun 2013, 09:15 PM
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)
public class NullableFkModel
{
    [ScaffoldColumn(false)]
    public int Id { get; set; }
    public string Name { get; set; }
    [UIHint("Fk")]
    public int? FkId { get; set; }
}
Editor template for the nullable FK property is:
@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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 18 Jun 2013, 12:38 PM
Hi Adam,

 
I would suggest to check this CodeLibrary demo which demonstrates how to implement custom binding and disable the default value binding for a DropDownList(or ComboBox) in order to always set the value. This approach can be used to avoid the default value binding behavior to update the field with the selected item when the initial value is null.

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adam
Top achievements
Rank 1
answered on 18 Jun 2013, 07:17 PM
Thanks Vladimir, I have tested with the custom binder and it is working so far.

Is there a plan to support nullable binding out of the box? It seems like a basic need for many. At least in this case it seems like it would be easy to use ViewData.ModelMetadata.IsNullableValueType in your editor templates to support it.
0
Vladimir Iliev
Telerik team
answered on 19 Jun 2013, 06:57 AM
Hi Adam,

 
I would suggest to share your idea at KendoUI UserVoice to allow other users vote for it. Most voted ideas are included in next KendoUI releases.

Kind Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Adam
Top achievements
Rank 1
answered on 19 Jun 2013, 02:53 PM
I have added a suggestion here: http://feedback.kendoui.com/forums/127393-kendo-ui-feedback/suggestions/4101412-support-nullable-binding-out-of-the-box
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Adam
Top achievements
Rank 1
Share this question
or