public ActionResult Index()
    {
        ListBoxModel model = new ListBoxModel();

        model.Names = new List <string>();
        model.Names.Add("Rami");
        return(View(model));
    }
        public ActionResult Index()
        {
            ListBoxModel model = new ListBoxModel {
                LeftListBoxItems = item.GetAllItem(), RightListBoxItems = new List <item>()
            };

            return(View(model));
        }
        void MoveToLeft(ListBoxModel model)
        {
            if (model.RightSelectItemID != null)
            {
                var prods = item.GetAllItem().Where(p => model.RightSelectItemID.Contains(p.Id));
                model.LeftListBoxItems.AddRange(prods);

                model.RightListBoxItems.RemoveAll(p => model.RightSelectItemID.Contains(p.Id));
                model.RightSelectItemID = null;
            }
        }
 public ActionResult Index(ListBoxModel model, string ToRight, string ToLeft)
 {
     ModelState.Clear();
     //To get the two list box items' information
     RestoreSavedState(model);
     if (ToRight != null)
     {
         MoveToRight(model);
     }
     else
     {
         MoveToLeft(model);
     }
     sortBoxList(model);
     //To Save the two list box items' information
     SaveState(model);
     return(View(model));
 }
        void RestoreSavedState(ListBoxModel model)
        {
            model.RightListBoxItems = new List <item>();
            model.LeftListBoxItems  = new List <item>();
            //get the previously stored items
            if (!string.IsNullOrEmpty(model.SavedRightInfo) && !string.IsNullOrEmpty(model.SavedLeftInfo))
            {
                string[] itemIds = model.SavedRightInfo.Split(',');
                var      prods   = item.GetAllItem().Where(p => itemIds.Contains(p.Id.ToString()));
                model.RightListBoxItems.AddRange(prods);


                itemIds = model.SavedLeftInfo.Split(',');
                prods   = item.GetAllItem().Where(p => itemIds.Contains(p.Id.ToString()));
                model.LeftListBoxItems.AddRange(prods);
            }
            else
            {
                model.LeftListBoxItems = item.GetAllItem();
            }
        }
示例#6
0
 public IActionResult ListBox(ListBoxModel model)
 {
     return(View(model));
 }
 public ActionResult Submit(ListBoxModel model)
 {
     return(null);
 }
 void SaveState(ListBoxModel model)
 {
     //create comma delimited list of item ids
     model.SavedRightInfo = string.Join(",", model.RightListBoxItems.Select(p => p.Id.ToString()).ToArray());
     model.SavedLeftInfo  = string.Join(",", model.LeftListBoxItems.Select(p => p.Id.ToString()).ToArray());
 }
 public void sortBoxList(ListBoxModel model)
 {
     model.RightListBoxItems = model.RightListBoxItems.OrderBy(p => p.Name.Length).ThenBy(p => p.Name).ToList();
     model.LeftListBoxItems  = model.LeftListBoxItems.OrderBy(p => p.Name.Length).ThenBy(p => p.Name).ToList();
 }