I have an MVC 4, EF 5 model first project with these models:
- Contractor
- Profile
Between these two is a many-to-many relation. (in the background EF generates a ContractorProfiles table and I'm can get a list of profiles for a contractor by calling Contractor.Profiles)
I would like to use the MultiSelectFor to be able to select one or more profiles for my contractor and directly bind it to my viewmodel but I don't know how to do this.
How can this be done?
I would like to use the MultiSelectFor to be able to select one or more profiles for my contractor and directly bind it to my viewmodel but I don't know how to do this.
How can this be done?
5 Answers, 1 is accepted
0
Hello Erik,
Daniel
Telerik
The MultiSelectFor helper should automatically bind the values based on model collection of objects in the latest release. Which version are you using? If you are using the latest release then could you provide the code that you are currently using and more detailed information about the problem.
Regards,Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Erik
Top achievements
Rank 1
answered on 11 Oct 2013, 03:24 PM
Hi Daniel,
Yes, I'm using the latest version. Like I said, I don't know how to do this so I do not have an example.
In the end I just used the MultiSelect and some extra code on the server to get it working.
But I would like to see an example of the MultiSelectFor.
So the data from my list is in Model.Profiles and the result from the list should be bound to Contractor.Profiles (this is a collection generated by EF)
Yes, I'm using the latest version. Like I said, I don't know how to do this so I do not have an example.
In the end I just used the MultiSelect and some extra code on the server to get it working.
@(Html.Kendo().MultiSelect()
.Name(
"Contractor.Profile"
)
.BindTo(Model.ProfileList)
.DataValueField(
"Id"
)
.Value(Model.CurrentProfiles)
)
So the data from my list is in Model.Profiles and the result from the list should be bound to Contractor.Profiles (this is a collection generated by EF)
0
Hello,
Daniel
Telerik
You should use a ViewModel for the MultiSelect data. Otherwise, the JavaScriptSerializer will thrown an exception for circular references. I attached a sample project using the MultiSelectFor helper and Entity Framework for the Northwind database.
Regards,Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mike
Top achievements
Rank 2
answered on 05 Nov 2014, 10:41 AM
Can I get a copy of that sample project?
0
Hello Mike,
The project is attached but for some reason it seems that it is not publicly visible. I have reattached it to this post.
Regards,
Daniel
Telerik
The project is attached but for some reason it seems that it is not publicly visible. I have reattached it to this post.
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!