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

Group DropDownListFor options

1 Answer 108 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Christos
Top achievements
Rank 1
Christos asked on 08 Jul 2019, 01:43 PM

     Hello,

 

I would like to ask if it's possible to group DropDownListFor options as it is described in this link (https://demos.telerik.com/aspnet-core/dropdownlist/grouping), but for DropDownListFor?

 

Thank you.

 

e.g. How can I group my dropdown options by LineOfBusinessCategory?

@(Html.Kendo().DropDownListFor(m => m.CompanyHasLineofBusiness.LineOfBusinessID)
                                                      .DataTextField("LineOfBusinessName")
                                                      .DataValueField("LineOfBusinessID")
                                                      .FixedGroupTemplate("LineOfBusinessCategory")
                                                      .DataSource(source =>
                                                      {
                                                          source.Custom();
                                                          source.ServerFiltering(true);
                                                          source.Read(read =>
                                                          {
                                                              read.Action("LineOfBusinessNameList", "Midas").Type(HttpVerbs.Post);
                                                          });
                                                      })
                                                      .HtmlAttributes(new { style = "width: 100%", @validationMessage = "Mandatory" })
                              )

 

1 Answer, 1 is accepted

Sort by
0
Christos
Top achievements
Rank 1
answered on 08 Jul 2019, 01:51 PM

This is the answer :)

@(Html.Kendo().DropDownListFor(m => m.CompanyHasLineofBusiness.LineOfBusinessID)
                                                      .DataTextField("LineOfBusinessName")
                                                      .DataValueField("LineOfBusinessID")
                                                       .DataSource(source => source
                                                       .Custom()
                                                       .Group(g => g.Add("LineOfBusinessCategory", typeof(string)))
                                                       .Transport(transport => transport
                                                       .Read(read =>
                                                       {
                                                           read.Action("LineOfBusinessNameList", "Midas").Type(HttpVerbs.Post);
                                                       })))
                                                      .HtmlAttributes(new { style = "width: 100%", @validationMessage = "Mandatory" })
                              )

Tags
DropDownList
Asked by
Christos
Top achievements
Rank 1
Answers by
Christos
Top achievements
Rank 1
Share this question
or