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:
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?
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>