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

Combobox unable to post long/int in grid popup window

4 Answers 83 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 20 Feb 2013, 08:55 PM
The combobox only seems to post its value if the property is of type string when it's in a grid popup window.  In my case i'm using ServerFiltering(true) on the combobox.  The value should be a long and the property is a long, but unless i make the property a string the value will not post. 

Attached a sample project.

Sorry if this is repeated somewhere, I searched for a while.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 22 Feb 2013, 07:11 PM
Hello Chris,

Since the ComboBox is used as an EditorTemplate, you should declare it using the ComboBoxFor method and bind it to the edited property. In the current scenario, it should be like this:

@(Html.Kendo().ComboBoxFor(model=>model.OccurenceId)
  .DataTextField("OccurenceText")
  .DataValueField("OccurenceId")
  ...
)

The name of the ComboBox should be the same as the property name.

 

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 22 Feb 2013, 07:17 PM
So you can't post the combobox to a property that isn't the DataValueField property?  Although, you can do it if the property is a string?

Edit:  That doesn't seem to work either. Attached.
0
Dimiter Madjarov
Telerik team
answered on 26 Feb 2013, 01:56 PM
Hi Chris,

This behavior is expected with the modified implementation. The ComboBox is bound to the ResourceId, which is a nullable property of the Occurence class, but there is no DefaultValue specified for it in the ModelDescriptor. You should add it in the Grid dataSource initialization to fix it.

E.g.

.DataSource(dataSource => dataSource
        .Ajax()
            .Model(model =>
            {
                model.Id(r => r.ThePrimaryId);
                model.Field(r => r.OccurenceId).DefaultValue(1);
                model.Field(r => r.ResourceId).DefaultValue(1);
            })
            .Read(read => read.Action("Occurence_Read", "Home"))
            .Create(read => read.Action("Occurence_Create", "Home"))
    )

  Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 27 Feb 2013, 12:17 PM
For anyone else with a similar problem, Dimiter recommended this and it seems to be the best solution for an Add. 

Hopefully, DefaultValue can be changed to allow null.

<script type="text/javascript">
    function Edit(e)
    {
        e.model.set("ResourceId", null);
    }
</script>
Tags
ComboBox
Asked by
Chris
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Chris
Top achievements
Rank 1
Share this question
or