Combobox unable to post long/int in grid popup window

5 posts, 0 answers
  1. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 20 Feb 2013 Link to this post

    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.
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 22 Feb 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 22 Feb 2013 Link to this post

    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.
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 26 Feb 2013 Link to this post

    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!
  6. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 27 Feb 2013 Link to this post

    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>
Back to Top
UI for ASP.NET MVC is VS 2017 Ready