当前位置: 首页>>代码示例>>C#>>正文


C# SelectList.Count方法代码示例

本文整理汇总了C#中System.Web.Mvc.SelectList.Count方法的典型用法代码示例。如果您正苦于以下问题:C# SelectList.Count方法的具体用法?C# SelectList.Count怎么用?C# SelectList.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.SelectList的用法示例。


在下文中一共展示了SelectList.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AdminViewModel

 /// <summary>
 /// Constructor used to initialize object properties at construction.
 /// </summary>
 /// <param name="userModels">List of users that will be displayed on an admin view page.</param>
 /// <param name="roleList">List of the system roles that will be used in a dropdown box</param>
 /// <param name="selectedRole">Selected role to default the drop down list to.</param>
 public AdminViewModel(List<UserInfoModel> userModels, SelectList roleList, string selectedRole)
 {
     if(userModels != null && userModels.Count > 0 && roleList != null && roleList.Count() > 0 && !string.IsNullOrEmpty(selectedRole)) {
         Users = userModels;
         RoleList = roleList;
         SelectedRole = selectedRole;
     }
 }
开发者ID:trwq63,项目名称:med656,代码行数:14,代码来源:AdminViewModel.cs

示例2: Create

        // GET: Settings/Create
        public ActionResult Create()
        {
            sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser);
            if (userDetails == null)
                userDetails = new sdtoUser();

            var items = new SelectList(db.Companies, "CompanyId", "CompanyName");
            ViewBag.CompanyList = items;
            if (items == null || items.Count() == 0)
            {
                TempData["ERR_PREMATURE_MESSAGE"] = "Please register a company for configuring settings";
                return RedirectToAction("Create", "Company");
            }

            var settings = db.GeneralSettings.Where(x => x.CompanyId == userDetails.CompanyId);
            if (settings != null && settings.Count() > 0)
                return EditOnCreate(settings.FirstOrDefault(x => x.CompanyId == userDetails.CompanyId) as sdtoSettings);
            else
                return View(new sdtoSettings() { CompanyId = userDetails.CompanyId, BankCharges = 0, BankInterest = 0 });
        }
开发者ID:NexvisionInfoSolutions,项目名称:Nexy,代码行数:21,代码来源:SettingsController.cs

示例3: EditTestLockError

        public void EditTestLockError()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Order_ItemController target = new Order_ItemController();
            int expected = orderItem1.id;
            orderItem1.version += 5;
            SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id", orderItem1.menu_item_id);
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id", orderItem1.order_id);
            ViewResult actual;

            // Act
            actual = (ViewResult)target.Edit(orderItem1);

            // Assert
            Assert.AreEqual(expected, ((order_item)actual.ViewData.Model).id);

            SelectList actualMenuList = actual.ViewBag.menu_item_id;
            Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType());
            Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count());

            SelectList actualOrderList = actual.ViewBag.order_id;
            Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType());
            Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:28,代码来源:Order_ItemControllerTest.cs

示例4: CreateViewTest

        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            RestaurantUserController target = new RestaurantUserController();
            SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name");
            SelectList expectedUsersList = new SelectList(db.users.Where(u => u.user_role == (int)SiteRoles.Restaurant
                || u.user_role == (int)SiteRoles.Admin), "id", "username");
            ViewResult actual;

            //Act
            actual = (ViewResult)target.Create();

            //Assert
            SelectList actualRestoList = actual.ViewBag.restaurant_id;
            Assert.AreEqual(expectedRestoList.GetType(), actualRestoList.GetType());
            Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count());

            SelectList actualUserList = actual.ViewBag.user_id;
            Assert.AreEqual(expectedUsersList.GetType(), actualUserList.GetType());
            Assert.AreEqual(expectedUsersList.Count(), actualUserList.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:22,代码来源:RestaurantUserControllerTest.cs

示例5: CreateViewTest

        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            Order_ItemController target = new Order_ItemController();
            SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id");
            SelectList expectedOrderList = new SelectList(db.orders, "id", "id");
            ViewResult actual;

            //Act
            actual = (ViewResult)target.Create();

            //Assert
            SelectList actualMenuList = actual.ViewBag.menu_item_id;
            Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType());
            Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count());

            SelectList actualOrderList = actual.ViewBag.order_id;
            Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType());
            Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:21,代码来源:Order_ItemControllerTest.cs

示例6: CreateTestInvalidStateModel

        public void CreateTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem2.item_id);
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem2.menu_category_id);
            ViewResult actual;

            // Act
            actual = (ViewResult)target.Create(menuItem2);

            // Assert
            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:25,代码来源:Menu_ItemControllerTest.cs

示例7: EditTestLockFailure

        public void EditTestLockFailure()
        {
            // Arrange
            db = new touch_for_foodEntities();
            Menu_ItemController target = new Menu_ItemController();
            int expected = menuItem1.id;
            SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem1.item_id);
            SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem1.menu_category_id);
            ViewResult actual;
            menuItem1.version += 5;

            // Act
            actual = (ViewResult)target.Edit(menuItem1);

            // Assert
            Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id);

            SelectList actualItemList = actual.ViewBag.item_id;
            Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType());
            Assert.AreEqual(expectedItemList.Count(), actualItemList.Count());

            SelectList actualCategoryList = actual.ViewBag.menu_category_id;
            Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType());
            Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:28,代码来源:Menu_ItemControllerTest.cs

示例8: CreateViewTest

        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", db.restaurants.First().id);

            //Act
            ViewResult actual = (ViewResult)target.Create();

            //Assert
            Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.resto_id.GetType());
            SelectList actualRestoList = actual.ViewBag.resto_id;
            Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:14,代码来源:MenuControllerTest.cs

示例9: DropInspectors

        public ActionResult DropInspectors(int id, FormCollection form)
        {
            try
            {
                Store store = db.Stores.Find(id);
                int InspectorID;
                int.TryParse(Request.Form["User_UserID"], out InspectorID);  //获取要被删除的检查员的用户ID
                User Inspector = db.Users.Find(InspectorID);
                store.Inspectors.Remove(Inspector);
                db.Entry(store).State = EntityState.Modified;
                db.SaveChanges();

                //方便连续删除检查员,提示删除成功后,停留DropInspectors视图,同时返回未被删除的Inspectors
                SelectList Inspectors = new SelectList(store.Inspectors.ToList(), "UserID", "UserName");
                if (Inspectors.Count() == 0) Inspectors = null;
                ViewBag.User_UserID = Inspectors;
                ViewData["Statue"] = "Drop Inspector" + Inspector.UserName + " succeed";
                return View(store);
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Server Error.");
            }
            return RedirectToAction("Index");
        }
开发者ID:JasonZHOU92,项目名称:Retail-Management,代码行数:25,代码来源:StoreController.cs

示例10: EditTestInvalidStateModel

        public void EditTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            long expected = friendship1.id;
            SelectList expectedUser1List = new SelectList(db.users, "id", "username", user1);
            SelectList expectedUser2List = new SelectList(db.users, "id", "username", user2);
            friendship1.second_user = user3.id;
            target.ModelState.AddModelError("error", "ModelState is invalid");

            // Act
            ViewResult actual = (ViewResult)target.Edit(friendship1);

            // Assert
            SelectList actualUser1List = actual.ViewBag.first_user;
            SelectList actualUser2List = actual.ViewBag.second_user;
            string errorMsg = actual.ViewBag.Error;
            Assert.AreEqual(((friendship)actual.Model).id, expected);
            Assert.AreEqual(expectedUser1List.GetType(), actualUser1List.GetType());
            Assert.AreEqual(expectedUser2List.GetType(), actualUser2List.GetType());
            Assert.AreEqual(expectedUser1List.Count(), actualUser1List.Count());
            Assert.AreEqual(expectedUser2List.Count(), actualUser2List.Count());
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:25,代码来源:FriendshipControllerTest.cs

示例11: Register

        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FullName =  model.FullName, Status = UserStatus.Offline };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    var currentUser = UserManager.FindByName(user.UserName);
                    var roleresult = UserManager.AddToRole(currentUser.Id, model.Role.ToString());
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            var adminUsers = UserManager.Users.Where(u => u.Roles.Any(r => r.RoleId == "2")).ToList();
            var selectListUser = new SelectList(adminUsers, "Id", "FullName");
            if (selectListUser.Count() == 0)
            {
                List<SelectListItem> items = new List<SelectListItem>();

                var emptyItem = new SelectListItem()
                {
                    Text = "None",
                    Value = ""
                };
                items.Add(emptyItem);
                selectListUser = new SelectList(adminUsers, "Value", "Text");
            }
            ViewBag.AdminUsers = selectListUser;
            return View(model);
        }
开发者ID:quynhlx,项目名称:SignalRChatHub,代码行数:40,代码来源:AccountController.cs

示例12: EditTest

        public void EditTest()
        {
            //Setup
            int expected = table1.id;
            SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", table1.restaurant_id);

            //Act
            ViewResult actual = (ViewResult)target.Edit(table1.id);

            //Assert
            Assert.AreEqual(((table)actual.Model).id, expected);
            Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.restaurant_id.GetType());
            SelectList actualRestoList = actual.ViewBag.restaurant_id;
            Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:15,代码来源:TableControllerTest.cs

示例13: CreateViewTest

        public void CreateViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            FriendshipController target = new FriendshipController();
            SelectList expectedUserList = new SelectList(db.users, "id", "username");

            //Act
            ViewResult actual = (ViewResult)target.Create();

            //Assert
            SelectList actualUser1List = actual.ViewBag.first_user;
            SelectList actualUser2List = actual.ViewBag.second_user;
            Assert.AreEqual(expectedUserList.GetType(), actualUser1List.GetType());
            Assert.AreEqual(expectedUserList.GetType(), actualUser2List.GetType());
            Assert.AreEqual(expectedUserList.Count(), actualUser1List.Count());
            Assert.AreEqual(expectedUserList.Count(), actualUser2List.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:18,代码来源:FriendshipControllerTest.cs

示例14: EditTableTestInvalidStateModel

        public void EditTableTestInvalidStateModel()
        {
            // Arrange
            db = new touch_for_foodEntities();
            target.ModelState.AddModelError("error", "ModelState is invalid");
            int expected = table1.id;
            SelectList expectedRestos = new SelectList(db.restaurants, "id", "name", table1.restaurant_id);
            ViewResult actual;

            // Act
            actual = (ViewResult)target.Edit(table1);

            // Assert
            Assert.AreEqual(expected, ((table)actual.ViewData.Model).id);

            SelectList actualRestos = actual.ViewBag.restaurant_id;
            Assert.AreEqual(expectedRestos.GetType(), actualRestos.GetType());
            Assert.AreEqual(expectedRestos.Count(), actualRestos.Count());

            string errorMsg = actual.ViewBag.Error;
            Assert.IsNotNull(errorMsg); //error message is sent to view
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:22,代码来源:TableControllerTest.cs

示例15: EditViewTest

        public void EditViewTest()
        {
            //Arrange
            db = new touch_for_foodEntities();
            SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", menu1.id);

            //Act
            ViewResult actual = (ViewResult)target.Edit(menu1.id);

            //Assert
            Assert.AreEqual(((menu)actual.Model).id, menu1.id);
            Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.resto_id.GetType());
            SelectList actualRestoList = actual.ViewBag.resto_id;
            Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count());
        }
开发者ID:pmoda,项目名称:TFFCode,代码行数:15,代码来源:MenuControllerTest.cs


注:本文中的System.Web.Mvc.SelectList.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。