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

Kendo DropDownListFor in Grid popup Edit template

2 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 04 Feb 2014, 10:46 AM
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 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 Feb 2014, 07:01 AM
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!
0
Benjamin
Top achievements
Rank 1
answered on 06 Feb 2014, 09:51 AM
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.
Tags
Grid
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Benjamin
Top achievements
Rank 1
Share this question
or