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

Sending values to action

2 Answers 110 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 2
Marcus asked on 17 Jul 2013, 01:40 PM
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 Answers, 1 is accepted

Sort by
0
Marcus
Top achievements
Rank 2
answered on 17 Jul 2013, 08:23 PM
Solved it.
0
Danilo
Top achievements
Rank 1
answered on 04 Nov 2013, 01:36 PM
Hi! How did you solve this? I am having the same issue..

Thanks!
Tags
MultiSelect
Asked by
Marcus
Top achievements
Rank 2
Answers by
Marcus
Top achievements
Rank 2
Danilo
Top achievements
Rank 1
Share this question
or