Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi every one,
I have a problem with the values returned from a multiple selected list in MVC.
the returned values to the controller are as followes:

C#
SelectedCode[0] = "System.Collections.Generic.List`1[System.String]"
SelectedCode[1] = "Value1"
SelectedCode[2] = "Value2"


I only need the value in index 1 and 2 and not the value of 0. How do I get rid of the value in index 0?

C#
Model:
        public List<string> SelectedCode { get; set; }



        public Collection<CodeDescription> CodeList { get; internal set; }

Controller:
            model.SubLevelList.Add(new CodeDescription("1", "Value1"));
            model.SubLevelList.Add(new CodeDescription("2", "Value2"));

Class:
    public class CodeDescription
    {
        public CodeDescription();
        public CodeDescription(string code, string description);

        public string Code { get; set; }
        public string Description { get; set; }
    }


view 
<div class="row padding5">
  @Html.LabelFor(model => model.SelectedCode, htmlAttributes: new { @class = "form-label", @style = "" })
  <div class="input-control full-size" data-role="select">
       @Html.HiddenFor(model => model.SelectedCode)
       @Html.DropDownListFor(model => model.SelectedCode, new MultiSelectList(Model.CodeList.ToList(), "Code", "Description", Model.SelectedCode), "Select a Value", new { multiple = "multiple", @class = "form-control", @style = "width:300px" })
  </div>
@Html.ValidationMessageFor(model => model.SelectedCode, "", new { @class = "fg-red" })
</div>
Posted
Updated 21-Dec-15 2:35am
v2
Comments
John C Rayan 21-Dec-15 9:28am    
what is @Html.HiddenFor(model => model.SelectedCode) doing there ?
@Html.HiddenFor(model => model.SelectedCode), remove it and see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900