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

Binding selected value of dropdownlist in editor template to model of main view

3 Answers 663 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 16 Jul 2013, 02:31 PM
I have a Kendo grid on one view that has a column that needs to be a dropdownlist when inline editing.  I've set the editor template name on the column to a partial view that I created, and that all seems to be working.

The part that is not working is when you change the value of the dropdownlist and click the Update button in the command button column.  The selected value is not being applied to the model.
@(Html.Kendo().DropDownList()
            .Name("divisionCombobox")
            .BindTo("#=UserViewModel.DivisionId")
            .HtmlAttributes(new { style = "width:250px" })
            .DataTextField("DisplayName")
            .DataValueField("Id")
            .AutoBind(true)
            .DataSource(source => source
                .Read(read => read.Action("ListDivisions", "Security"))
                .ServerFiltering(true))
)

Is the BindTo property not the right one to use?

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 16 Jul 2013, 07:07 PM
Finally figured it out.  In case anyone else runs into this, the Name attribute of the control on the editor template needs to be the name of the model's property that you are trying to bind it to.
0
Tamas
Top achievements
Rank 1
answered on 16 Feb 2016, 04:37 PM
Thanks. This really helped me now!
0
Tamas
Top achievements
Rank 1
answered on 16 Feb 2016, 06:18 PM

Using 

@(Html.Kendo().DropDownListFor(m => m.Property) ...

works too. And there is no need to use the BindTo method.

Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 1
Tamas
Top achievements
Rank 1
Share this question
or