How do I post selected values to controller?

2 posts, 0 answers
  1. Mike
    Mike avatar
    17 posts
    Member since:
    Feb 2015

    Posted 02 Mar 2015 Link to this post

    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))


    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) 

                return View("ReportDetail", reportView2);

            return Redirect("/Report/Search");

  2. Georgi Krustev
    Georgi Krustev avatar
    3747 posts

    Posted 04 Mar 2015 Link to this post

    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.

    Georgi Krustev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top