MultiSelectFor and Values

4 posts, 0 answers
  1. Cynthia
    Cynthia avatar
    13 posts
    Member since:
    Apr 2012

    Posted 30 Apr 2013 Link to this post

    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.
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 02 May 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. anthony
    anthony avatar
    6 posts
    Member since:
    Apr 2013

    Posted 09 Nov 2013 Link to this post

    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?
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 12 Nov 2013 Link to this post

    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!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready