Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am saving the selected ListBox items values in a comma separated string.

C#
private string fabricString(IEnumerable<string> fabricsList)
    {
        string str = string.Join(",", fabricsList);
        return str;
    }



For Example str = "1,3"

Now in edit controller how can I want to select Text in ListBox based on the above string

What I have tried:

C#
public ActionResult Edit(int? id)
    {

        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        fa_Data fad_Data = db.fad_Data.Find(id);
        fad_Data.sizeList = fad_Data.size.Split(',').ToList().Select(s => new SelectListItem() { Text = s, Value = s });
        if (fad_Data == null)
        {
            return HttpNotFound();
        }
        return View(fad_Data);
    }



Using above code I get the error

An exception of type 'System.ArgumentNullException' occurred in System.Web.Mvc.dll but was not handled in user code at line

C#
fad_Data.sizeList = fad_Data.size.Split(',').ToList().Select(s => new SelectListItem() { Text = s, Value = s });
Posted
Updated 4-May-17 19:28pm
v2

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