4

I have a KendoUI dropdownlist as follows:

@(Html.Kendo().DropDownList()
                                  .Name("DeviceInterfaces")
                                  .OptionLabel("Select interface...")
                                  .DataTextField("Name")
                                  .DataValueField("Id")
                                  .DataSource(source => source.Read(read => read.Action("GetCascadeDeviceInterfaces", "EventTriggers")))
                            )

It's a cascading dropdownlist, how do I set whatever the user selects to the property of my model?

tereško
  • 58,060
  • 25
  • 98
  • 150
Null Reference
  • 11,260
  • 40
  • 107
  • 184

1 Answers1

8

It's ok, I found out how to.

I have to use DropDownListFor instead of DropDownList, plus the .Name property has to match the Id of the model.

@(Html.Kendo().DropDownListFor(m => m.EventTrigger.TriggerType)
.Name("EventTrigger.EventType")
Null Reference
  • 11,260
  • 40
  • 107
  • 184
  • 5
    If you are binding to the property using this line of code .DropDownListFor(m => m.EventTrigger.TriggerType) this make calling .Name() redundant – SimonGates Nov 29 '12 at 14:28
  • 1
    If you set the Name (as of 2015) it breaks the binding - at least it broke mine – Andez Jun 06 '15 at 22:48
  • I had to set Name to the exact spelling of the property i was binding to on the viewModel in-order to save the selected value on the form – Sarah Oct 23 '18 at 08:01