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

Urgent: Post data back to controller in List<SomeClass>

2 Answers 74 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Ravinder
Top achievements
Rank 1
Ravinder asked on 08 Apr 2014, 02:04 AM
I posted the same my be in some wrong category. Please answer ASAP as I am in critical Situation.

Hi,
I am new to Kendo UI widgets and MVC4. I am using Razor View. I have a model Called Project. I have another model called Location. In Project model there is a property "List<LocationType> Locations". 

On my razor form i have "@model Model.Project" and one of my multiselect widget shows me location list. I have declared it "@(Html.Kendo().MultiSelectFor(model => model.LocanTypes)". Now when I try to get "Project.Locations" in controller in [HttpPost] action I get Project.Locations as null.

Model declaration on Razor Page: 
@model PestPec.Models.Project 

Multiselect declartion of Multiselect:
@(Html.Kendo().MultiSelectFor(model => model.LocanTypes)
                        .Name("LocationTypesMultiSelect")
                        .Placeholder("Select Location Type(s)")
                        .DataTextField("Name")
                        .DataValueField("ID")
                        .Filter(FilterType.Contains)
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("GetLocatinTypes", "Project");
                            });
                        }) 
                    ) 

Project.cs:
 public class Project
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int Type { get; set; }
        public string CreatedBy { get; set; }
        public List<Technician> Technicians{get; set;}
        public List<Route> Routes { get; set; }
        public List<ProjService> Services { get; set; }
        public List<Division> Divisions { get; set; }
        public List<Branch> Branches { get; set; }
        public List<LocationType> LocanTypes { get; set; }
        public String Country { get; set; }
        public String City { get; set; }

        [DisplayFormat(DataFormatString = "{0:MM/dd/yy}")]
        public DateTime CreatedDate { get; set; }

        [DisplayFormat(DataFormatString = "{0:MM/dd/yy}")]
        public DateTime LastUpdatedDate { get; set; }
    }

LocationType:
public class LocationType
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }

2 Answers, 1 is accepted

Sort by
0
Ravinder
Top achievements
Rank 1
answered on 08 Apr 2014, 03:00 AM
I changed my MultiSelect widget to: 

@(Html.Kendo().MultiSelectFor(model => model.Technicians)
                            .Name("Technicians")
                            .Placeholder("Select Technician(s)")
                            .DataTextField("Name")
                            .DataValueField("ID")
                            .Filter(FilterType.Contains)
                            .AutoBind(true)
                            .DataSource(source =>
                            {
                                source.Read(read =>
                                {
                                    read.Action("GetTechnicians", "Project");
                                })
                                .ServerFiltering(false);
                            })
                            .BindTo(Model.Technicians)          
                        )

Now I am getting "Technicians" object with 0 length instead of null.
0
Accepted
Daniel
Telerik team
answered on 09 Apr 2014, 04:33 PM
Hello,

The multiselect renders a select element and therefore only the values and not the entire items will be posted to the server when using a form. You should add a collection parameter of the value field type  to the action method with the same name as the property name in order to get the values on the server. 
public ActionResult Action(Project project, List<int> technicians)


Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
MultiSelect
Asked by
Ravinder
Top achievements
Rank 1
Answers by
Ravinder
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or