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

5 posts, 1 answers
  1. Adam
    Adam avatar
    24 posts
    Member since:
    Nov 2011

    Posted 14 Jun 2013 Link to this post

    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.
  2. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 18 Jun 2013 Link to this post

    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!
  3. Adam
    Adam avatar
    24 posts
    Member since:
    Nov 2011

    Posted 18 Jun 2013 Link to this post

    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.
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 19 Jun 2013 Link to this post

    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!
     
  5. Adam
    Adam avatar
    24 posts
    Member since:
    Nov 2011

    Posted 19 Jun 2013 Link to this post

    I have added a suggestion here: http://feedback.kendoui.com/forums/127393-kendo-ui-feedback/suggestions/4101412-support-nullable-binding-out-of-the-box
Back to Top