Sending values to action

3 posts, 1 answers
  1. Answer
    Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2013 Link to this post

    Hi,

    how do I send the current multiselect values to an asp.net mvc 4 action, as a IEnumerable<int>?

    I have:
    @(Html.Kendo().MultiSelect()
             .Name("Fields")
             .DataTextField("Name")
             .DataValueField("Id")
             .Value(ViewData["tagslist"] as IEnumerable<int>)
             .Filter(FilterType.Contains)
             .Placeholder("...")
             .Events(e =>
               {
                   e.Change("change_field");
               })
              .DataSource(source => {
                  source.Read(read =>
                  {
                      read.Action("ShowFields", "Folders");               
                  });
     
             })
    And I want to send the selected id's to an action which updates a model bound treeview:
    <div id="tree">
        @(
     Html.Kendo().TreeView()
                .Name("treeview")
                .ExpandAll(true)
                .TemplateId("treeview-template")
                .DragAndDrop(true)
                .BindTo(Model)
                 .Events(events => events
                        .DragEnd("onDragEnd")
                    )
                )
    </div>
    This is my action to create the new model for the treeview:
    public ActionResult Index(IEnumerable<int> fieldTags,int id = 1 )
    {
        IEnumerable<TreeViewItemModel> kendoModel = new List<TreeViewItemModel>();
        SopFolder kendoStartFolder = db.SopFolders.Where(r => r.Id == id).Take(1).Select(r => r).ToList()[0];           
         
        kendoModel = CreateKendoTree(kendoStartFolder, fieldTags);
     
        var SopFields =
         db.SopFields
        .Select(r => new
        {
            Value = r.Id,
            Text = r.Name
        });
        List<int> tagslist = new List<int>();
        foreach(var tag in SopFields)
        {
            tagslist.Add(tag.Value);
        }
        ViewData["tagslist"] = tagslist;
     
        if (Request.IsAjaxRequest())
        {
            return PartialView("_Tree", kendoModel);
        }
     
        return View(kendoModel);
    }

    So I need to do the following things:

    1. Get the MultiSelect currently selected id's data passed to the server as an IEnumerable<int> into the index action with ajax request
    2. Replace the content within the tree div with the new loaded treeview (if ajaxrequest, the action returns a partial view).

    I am having trouble with number 1. Please give me some advice on how to solve this.

    Thanks!

    Best regards,
    Marcus
  2. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2013 Link to this post

    Solved it.
  3. Kendo UI is VS 2017 Ready
  4. Danilo
    Danilo avatar
    2 posts
    Member since:
    Mar 2013

    Posted 04 Nov 2013 Link to this post

    Hi! How did you solve this? I am having the same issue..

    Thanks!
Back to Top