Unable to load saved value in MultiselectList chosen

69
January 09, 2019, at 05:10 AM

Hi Im new on using ListBox MultiSelectList , My problem is I cant fetch the value onload of my page, Here is my Code

In My Controller to Initialize the dropdown values

var getddlName = (from a in nameList
                                      where a.personId != null
                                      && a.personId != 0
                                      select new SelectListItem
                                      {
                                          Value = a.personId.ToString(),
                                          Text = a.personFullname
                                      }).ToList();
            ViewBag.ddlNameList = getddlName;

To Get the Saved value and Load it onload

if (ddlPersonIds != null)
            {
                List<string> list1 = new List<string>();
                var empIds = ddlPersonIds.Split(',');
                foreach(var c in empIds){
                list1.Add(c);
                }
               ViewBag.ddlPersonName = list1;
            }

And in my View here is how I pass the value to the MultiselectList

I created variable container in HTML head

var ddlNameList = ViewBag.ddlNameList;
var ddlPersonName = ViewBag.ddlPersonName;

and my MultiselectList

<div class="editor-field">

 @Html.ListBox("PersonIds", new MultiSelectList(ddlNameList, "Value", "Text", ddlPersonName), new { data_placeholder = "Select Employees...", @class = "chosen input-long-75", multiple = "multiple" })
                            </div>

EDIT: Even though I get the value in ddlPersonName it is unable to show and get selected in ddlNameList

Thanks

READ ALSO
End x-axis on last data point (scatter plot) for x,y numeric values

End x-axis on last data point (scatter plot) for x,y numeric values

When I plot a dataset of (x,y) floats on a scatter plot using ChartJS, I end up with extra space on my x-axis due to the step sizeCan I force it to end right on the last data point?

58
What do we actually import from Express in a Node.js program

What do we actually import from Express in a Node.js program

Usually when we import something in Node, we do something like:

81
Python: How do I pass variables between class instances or get the caller?

Python: How do I pass variables between class instances or get the caller?

In foo, I am doing something that produces "var1" being set to 1 In bar, I would like to access the contents of var1

65
Pull data from Active Directory with Python, Golang or Ruby on rails

Pull data from Active Directory with Python, Golang or Ruby on rails

I would like to make a web application which can pull data from Active DirectoryAt my work many developers recommend me to learn C# or Java mostly because they are using it

53