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

Get ListBox Items OnPost Event

1 Answer 264 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Iron
Iron
Iron
Mark asked on 20 Aug 2020, 08:41 PM

I am new to ASP.Core. How do I get the selected items from the "selected" ListBox on the OnPost event?

 

  @(Html.Kendo().ListBox()
        .Name("optional")
        .Toolbar(toolbar =>
        {
            toolbar.Position(ListBoxToolbarPosition.Right);
            toolbar.Tools(tools => tools
                .MoveUp()
                .MoveDown()
                .TransferTo()
                .TransferFrom()
                .TransferAllTo()
                .TransferAllFrom()
                .Remove()
            );
        })
        .ConnectWith("selected")
        .DataTextField("PlayerId")
        .DataTextField("Name")
        .Draggable(true)
        .DataSource(ds => ds.Ajax()
        .Read(r => r.Url("/League/PreDraftPage?handler=Read").Data("forgeryToken"))
)
    )
        @(Html.Kendo().ListBox()
        .Name("selected")
              .Toolbar(toolbar =>
        {
            toolbar.Position(ListBoxToolbarPosition.Right);
            toolbar.Tools(tools => tools
                .MoveUp()
                .MoveDown()
          );
        })
        .DataTextField("PlayerId")
        .DataTextField("Name")
        .BindTo(Model.LeaguePreDraftList)
        .Selectable(ListBoxSelectable.Multiple)
public void OnPost()
   {
       Guid leagueId;
       List<LeaguePreDraftViewModel> listModel;
 
 
       if (ModelState.IsValid)//save the data
       {
           var name = Request.Form["selected"];
           listModel = LeaguePreDraftList;
       }
       //leagueId = new Guid(id);
       //get data from page
 
   }
    )

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 25 Aug 2020, 11:29 AM

Hello Mark,

To access the selected items of a ListBox the select() method can be used:

Please take a look at the following Forum thread addressing this scenario: Passing data to the controller for 'selected' ListBox.

Let me know if this helps.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ListBox
Asked by
Mark
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nikolay
Telerik team
Share this question
or