send selected values to controller

4 posts, 0 answers
  1. Thomas
    Thomas avatar
    19 posts
    Member since:
    Aug 2013

    Posted 14 Oct 2013 Link to this post

    Hi Kendo community,

    I don't really understand how the selected objects out of a multiselect can be sent to the controller. The databinding out of the db works fine and I'm also able to select and remove items in the multiselect. By the way the multiselect is displayed inside a kendo window and posts with an ajax.beginform.

    My multiselect looks like this:

    @model SoftwareAdminInterface.Models.Administration.Pattern
    @
    using (Ajax.BeginForm("SetCombi", "Pattern", new { }, new AjaxOptions() { HttpMethod = "post", UpdateTargetId = "myContentPopupEditRole_div" }))
      
    @(Html.Kendo().MultiSelect()
                        .MaxSelectedItems(2)
                        .Name("RegExID")
                        .DataTextField("RegExName")
                        .DataValueField("RegExID")
                        .Placeholder("Select Patterns...")
                        .AutoBind(false)    
                        .DataSource(source => {
                            source.Read(read =>
                            {
                                read.Action("GetPatternsForCombi", "Pattern");
                            })
                        .ServerFiltering(true);
              })
        )

    What I want to do now is to pass the two selected RegExID's over to the controller. Controller action looks like this:
    [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult SetCombi([DataSourceRequest] DataSourceRequest request, List<Pattern> selectedPatterns)
            {
                SoftwareHelper helper = new SoftwareHelper();
     
                return PartialView("Combination");
            }

    basically I thought of getting the IDs from the List<Pattern>, but the list is null.
    any advise?

    thx in advance
    kind regards
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 16 Oct 2013 Link to this post

    Hello,

    The selected values will be posted when using a form and not the objects. Thus, you should use a collection of the value field type as parameter of the action. The action parameter name should also be the same as the multiselect name:

    public ActionResult SetCombi(List<RegExIDType> RegExID)
    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 25 Mar 2014 in reply to Daniel Link to this post

    Hey Daniel, I've got pretty much the same issue. I've got the control working and the form posting back to the controller but my list of objects always has a count of 0. In the above example, I don't quite understand what RegExIDType is. You say "use a collection of the value field type as parameter of the action". Well, the control is getting populated by "GetPatternsForCombi" which I'm assuming returns a List<Pattern> where RegExID is a property of Pattern as well as RegExName. So, how is RegExIDType different than Pattern?

    Thanks!
  5. Cool Breeze
    Cool Breeze avatar
    44 posts
    Member since:
    Jan 2014

    Posted 25 Mar 2014 in reply to Cool Breeze Link to this post

    Haha nevermind, I figured out what you mean (Guid, int etc). The actual data type of the field that the DataValueField is set to. Thanks!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready