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

MultiSelectFor and Values

3 Answers 298 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Cynthia
Top achievements
Rank 1
Cynthia asked on 30 Apr 2013, 02:12 PM
Here is a code snip:
@Html.Kendo().MultiSelectFor(model => model.Programs).BindTo((SelectList)ViewBag.Programs).DataTextField("Text").DataValueField("Id").Name("SelectedProgramIds ")
ViewBag.Programs is populated by:
Models.Program[] obj = model.List();
ViewBag.Programs = new SelectList(obj, "Id", "Name", project.Programs);

I'm also using:
public IEnumerable<String> SelectedProgramIds { get; set; }
.. as the property for the saved value in the model.

After I POST, SelectedProgramIds  contains the Text Name (but not values) of the entries in the MultiSelect control.  How can I get the Value as set by 
DataValueField(), instead of the DataTextField() after POST?

Also, when the control loads, how can existing items be selected?  Currently the box is empty.

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 02 May 2013, 11:45 AM
Hello Cynthia,

You code looks completely valid. You can use the network tab of your browser developer tools to see what exactly is being posted to the MVC controller.

I tried and on my side I am getting the IEnumerable of the values.

If you put this into a sample project we can check what is the exact reason for your misbehavior.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
anthony
Top achievements
Rank 1
answered on 09 Nov 2013, 09:03 PM
I have  a similar problem with 2013.2.716. The first time I submit my form, it POSTs the names. My view then displays a validation error, since it's expecting int values. The strange thing is that if I POST a second time, it correctly sends the values. Is this a known issue?
0
Petur Subev
Telerik team
answered on 12 Nov 2013, 03:58 PM
Hi Anthony,

We are not sure, send us small demo project so we can investigate further.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MultiSelect
Asked by
Cynthia
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
anthony
Top achievements
Rank 1
Share this question
or