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

EditorTemplates

2 Answers 189 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Louis asked on 03 Feb 2014, 05:55 PM
Hello,

Can you give me a complete example for dropdownlist in the editortemplates?

For now I have to change all my dropdownlist in every views like this and I Wonder if it's possible to define a generic way in EditorTemplates?

@(Html.Kendo().DropDownList()
    .Name("NoRisque") // Name of the widget should be the same as the name of the property
    .DataValueField("Value") // The value of the dropdown is taken from the EmployeeID property
    .DataTextField("Text") // The text of the items is taken from the EmployeeName property
    .BindTo((SelectList)ViewBag.NoSource) // A list of all employees which is populated in the controller
)

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Feb 2014, 03:29 PM
Hi Louis,

You can use the DropDownFor overload:

Before:
@(Html.Kendo().DropDownList()
    .Name("NoRisque")

After:
@(Html.Kendo().DropDownListFor(model => model)


Then the name of the widget will be induced from the model of the editor template.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 07 Feb 2014, 03:44 PM
Thank you Atanas,

In fact I complete your answer because I use ViewBag in my controller :

ViewBag.NoSource = new SelectList(db.Sources, "NoSource", "DescriptionSource_fr");

to populate the dropdownbox
@model object
 
@(
Html.Kendo().DropDownListFor(model => model)
   .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("")])
)
Tags
DropDownList
Asked by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Atanas Korchev
Telerik team
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or