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

How do I post selected values to controller?

1 Answer 1358 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 02 Mar 2015, 11:32 PM
I'm using the Kendo Multiselect widget, with server binding (i.e. not ajax), and MVC. It's not posting selected items to the controller. How do I do this? I've tried a few different ways, based on what I've read in your documentation, but none of them work, so rather than me continue guessing, how about if someone tells me how to do it :-)

Here's an excerpt from the View Model:

    public class ViewReportDetail
    {
        public List<CaType> CaTypes { get; set; }
        public List<CaType> AllCaTypes { get; set; }
        public int[] SelectedCaTypes { get; set; }
    }

Here's the multiselect widget in the view (strongly type as ViewReportDetail):

@using (Html.BeginForm("Save", "Report", FormMethod.Post))
{

    @(Html.Kendo().MultiSelect()
            .Name("CaTypes") 
            .DataTextField("Description") 
            .DataValueField("Id") 
            .BindTo(Model.AllCaTypes)
            .Value(Model.SelectedCaTypes)
    )
}

Here's the controller for the save (not much to see here):

    public ActionResult Save(ViewReportDetail reportView2)
    {

// I break here and inspect reportView2. CaTypes is empty, AllCaTypes is null, 
// and SelectedCaTypes does not show up at all in the inspector.

        if (ModelState.IsValid) 
        {
            CapService.Save2(reportView2);

        }
        else
        {
            return View("ReportDetail", reportView2);
        }

        return Redirect("/Report/Search");
    }


Thanks!
Mike

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 04 Mar 2015, 12:15 PM
Hello Mike,

The MultiSelect widget uses a Html Select element under the hood to persist the selected values and post them to the server if needed (forum thread). That being said, the widget can post only the selected values, like normal multiple select works. This can be observed in this code-library. Once the selected values are posted, you can retrieve the corresponding objects and populate the CaTypes field.

If you would like to post the whole objects, then you should use Ajax. Check this forum thread for more details.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MultiSelect
Asked by
Mike
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or