public ViewResult Binding(int id)
 {
     ViewBag.TopMenus = menuRepository.TopMenus;
     var topMenuBindings = menuRepository.TopMenuBindings.Where(x => x.TopMenuId == id);
     var model = new TopMenuViewModel(id, menuRepository.MenuCategories, topMenuBindings);
     return View(model);
 }
        public ActionResult Binding(TopMenuViewModel model)
        {
            ViewBag.TopMenus = menuRepository.TopMenus;
            //model.MenuCategories = menuRepository.MenuCategories;
            if (model.SelectedTopMenuId == 0)
            {
                TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Error, "No Top Menu is selected!");
                return View(model);
            }
            //else if (model.SelectedMenuCategoryIds == null || model.SelectedMenuCategoryIds.Count<int>() == 0)
            //{
            //    TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Error, "No Menu Categories are selected!");
            //    return View(model);
            //}

            if (ModelState.IsValid)
            {
                menuRepository.DeleteTopMenuBindings(menuRepository.TopMenuBindings.Where(x => x.TopMenuId == model.SelectedTopMenuId));
                menuRepository.SaveTopMenuBinding(model.SelectedTopMenuId, model.MenuCategories.Where(x => x.Selected).Select(x => x.MenuCategoryId).ToArray());                

                TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Success, string.Format("{0} has been saved!", model.SelectedTopMenuId));
                //if (String.IsNullOrEmpty(model.ControllerName))
                //    return RedirectToAction("List"); //Return to current controller
                //else
                //    return RedirectToAction("List", model.ControllerName); //Return to User controller
                return View(model);
            }
            else
            {
                //There is something wrong with the data values
                TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Error, "There is something wrong with the data values, please check!");
                return View(model);
            }
        }