Kendo DropDownListFor in Grid popup Edit template

3 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    5 posts
    Member since:
    Dec 2013

    Posted 04 Feb 2014 Link to this post

    I have a grid that uses the same template for editing and creating a new user record.
    Everything works fine when editing but for some reason when creating a new user the lanuageId is not being returned when posting the data back.

    All of the other fields are binding fine but no matter what the value selected in the dropdownlist the value 0 is being returned.
     
    @(Html.Kendo().DropDownListFor(m => m.LanguageId)
                      .DataTextField("Name") //Specifies which property of the Product to be used by the dropdownlist as a text.
                      .DataValueField("Id") //Specifies which property of the Product to be used by the dropdownlist as a value.
                      .HtmlAttributes(new { @class = "form-control" })
                      .DataSource(source => source.Read(read => read.Action("GetLanguageValues", "Account")))

    The form works perfectly fine when editing.

    What am I doing wrong?
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 06 Feb 2014 Link to this post

    Hello Benjamin,

    I assume that this is happening because you are missing a default value for that field and the whole dataItem of the DropDownList is assigned as value. Could you please try to define default value like so:

    .DataSource(dataSource => dataSource       
            .Ajax()        
            .Batch(true)
            .PageSize(20)
            .ServerOperation(false)               
            .Events(events => events.Error("error_handler"))
            .Model(model => {
                model.Id(p => p.ProductID);
                model.Field(p=>p.CategoryID).DefaultValue(5);
            })

    Let me know your findings.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Benjamin
    Benjamin avatar
    5 posts
    Member since:
    Dec 2013

    Posted 06 Feb 2014 in reply to Petur Subev Link to this post

    It seems like setting the default value seems to have resolved the issue, although I'm not sure exactly why since there is always a selected value that I thought should have been returned anyway.

    Anyway it works.

    Thank you.
Back to Top