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


C# Mvc.SelectListItem类代码示例

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


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

示例1: HydrateIndexModelShouldSetTheCreditCardTypesAndMembershipOptions

        public void HydrateIndexModelShouldSetTheCreditCardTypesAndMembershipOptions()
        {
            var indexModel = new IndexModel();

            var membershipOffers = new MembershipOffer[0];

            _mockOrderRepository.Setup(
                repos => repos.GetAllActiveMembershipOffers())
                .Returns(membershipOffers);

            var membershipOptionModels = new MembershipOptionModel[0];

            _mockIndexModelMapper.Setup(
                mapper => mapper.MapDomainToModels(
                    membershipOffers))
                .Returns(membershipOptionModels);

            var selectListItems = new SelectListItem[0];

            _mockCreditCardListItemMapper.Setup(
                mapper => mapper.MapCreditCardsToListItems(
                    It.IsAny<CreditCardType[]>()))
                .Returns(selectListItems);

            _indexModelRepository.HydrateIndexModel(
                indexModel);

            Assert.That(indexModel.MembershipOptions, Is.EqualTo(membershipOptionModels));
            Assert.That(indexModel.CreditCardTypes, Is.EqualTo(selectListItems));
        }
开发者ID:linus123,项目名称:TDDWithMvc,代码行数:30,代码来源:IndexModelRepositoryTests.cs

示例2: ConvertDataTableToSelectListItemsList

        //Pull back the types of invoices to allow the user to select them
        /// <summary>
        /// Converts DataTable To SelectListItems so can be bound to MVC control
        /// </summary>
        /// <param name="theDataTable"></param>
        /// <param name="theSelectListItemsList"></param>
        public static List<SelectListItem> ConvertDataTableToSelectListItemsList(DataTable theDataTable)
        {
            try
            {

                List<SelectListItem> theItemsToReturn = new List<SelectListItem>();
                theItemsToReturn.Add(new SelectListItem
                    {
                        Text = "Please Select",
                        Value = "Please Select"

                    });

                for (int i = 0; i < theDataTable.Rows.Count; i++)
                {
                    SelectListItem item = new SelectListItem();
                    //create a new item and add to the returnable list of SelectItems
                    item.Text = theDataTable.Rows[i].ItemArray[0].ToString();
                    item.Value = theDataTable.Rows[i].ItemArray[0].ToString();
                    theItemsToReturn.Add(item);

                }

                return theItemsToReturn;
            }
            catch (Exception ex)
            { throw ex; }
        }
开发者ID:nadavdrewe,项目名称:xero-aquarium-integration,代码行数:34,代码来源:MainController.cs

示例3: ClavesValores

        /// <summary>
        /// Método para recoger todas las claves de Riesgos y sus valores
        /// </summary>
        /// <returns></returns>
        public List<RiesgosValores> ClavesValores() {

            IQueryable<IGrouping<string, KRiesgo>> valores_riesgos = db.KRiesgo.GroupBy(z => z.id_riesgo);

            List<RiesgosValores> valores_final = new List<RiesgosValores>();

            foreach (IGrouping<string, KRiesgo> valor in valores_riesgos)
            {
                List<double> lista = valor.OrderBy(m => m.valor).Select(m => m.valor).Distinct().ToList();

                List<SelectListItem> l_tc = new List<SelectListItem>();
                foreach (double n in lista)
                {
                    SelectListItem item = new SelectListItem();
                    item.Value = n.ToString();
                    item.Text = n.ToString();
                    l_tc.Add(item);
                }

                RiesgosValores nuevo = new RiesgosValores();
                nuevo.clave = valor.Key;
                nuevo.valores = l_tc;

                valores_final.Add(nuevo);
            }

            return valores_final;
        
        }
开发者ID:heinerabella,项目名称:REDELECTRICA,代码行数:33,代码来源:ConsultaRiesgos.cs

示例4: PaymentTransferDetails

        public ActionResult PaymentTransferDetails(string transferId)
        {
            if (!ModelState.IsValid) return RedirectToAction("PaymentTransfer",
                new { message = string.Format("{0}: {1}", Resource.ErrorMessage, Resource.ErrorMessageInvalid)});

            int id;
            if (!int.TryParse(transferId, out id))
                return RedirectToAction("PaymentTransfer",
                    new { message = string.Format("{0}: {1}", Resource.ErrorMessage, Resource.ErrorMessageIdMustBeInteger)});

            var listUserPaySystem = new List<SelectListItem>();
            using (var ctx = DatabaseContext.Instance.Make())
            {
                foreach (var selectListItem in ctx.USER_PAYMENT_SYSTEM)
                {
                    var paymentSystemName = (PaymentSystem) selectListItem.SystemPayment;
                    var items = new SelectListItem
                        {
                            Text = string.Format("{0} {1}",selectListItem.PLATFORM_USER.Login,paymentSystemName),
            // ReSharper disable SpecifyACultureInStringConversionExplicitly
                            Value = selectListItem.Id.ToString().Trim()
            // ReSharper restore SpecifyACultureInStringConversionExplicitly
                        };
                    listUserPaySystem.Add(items);
                }
            }
            listUserPaySystem.Insert(0, new SelectListItem { Text = Resource.TitleSelectPaymentSystem, Value = "null" });
            ViewBag.listUserPaySystem = listUserPaySystem;

            var model = paymentTransferRepository.GetTransferById(id);
            return View(model);
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:32,代码来源:ManagementController.PaymentTransfer.cs

示例5: Create

        // GET: Department/Create
        public ActionResult Create()
        {
            //实现下拉列表
            List<SelectListItem> item = db.Departments.ToList().Select(c => new SelectListItem
            {
                Value = c.DepartmentId,//保存的值
                Text = c.Name//显示的值
            }).ToList();

            //增加一个null选项
            SelectListItem i = new SelectListItem();
            i.Value = "";
            i.Text = "-请选择-";
            i.Selected = true;
            item.Add(i);

            //传值到页面
            ViewBag.List = item;

            /*查找预留字段表,然后获取一个列表*/
            var recordList = (from p in db.ReserveFields where p.TableName == "Departments" select p).ToList();
            ViewBag.recordList = recordList;

            return View();
        }
开发者ID:kevinLeon,项目名称:Bonsaii_Nov_12,代码行数:26,代码来源:DepartmentController.cs

示例6: ListaDropSelect

        /// <summary>
        /// Lista de Grados_Proximidad para un dropdownlist selected value
        /// </summary>
        /// <returns></returns>
        public List<SelectListItem> ListaDropSelect(string id)
        {

            List<Grados_Proximidad> c_AFR = db.Grados_Proximidad.Where(m => m.activo == true).OrderBy(m => m.nombre).ToList();
            List<SelectListItem> l_AFR = new List<SelectListItem>();
            foreach (Grados_Proximidad n in c_AFR)
            {
                SelectListItem item = new SelectListItem();
                if (n.id == id)
                {
                    
                    item.Value = n.id;
                    item.Text = n.nombre;
                    item.Selected = true;
                }
                else {
                    item.Value = n.id;
                    item.Text = n.nombre;                
                }
                

                l_AFR.Add(item);
            }

            return l_AFR;
        }
开发者ID:heinerabella,项目名称:REDELECTRICA,代码行数:30,代码来源:Grado_Proximidad.cs

示例7: Index

        public ActionResult Index(string Message)
        {
            var data = new LocationIndexViewModel();
            data.SuccessMessage = Message;
            var locations = LocationBLO.Current.GetAllLocation();
            var list = locations.Where(x => x.RackStatus == Constants.StatusCode.RACK_AVAILABLE);
            var listavailablerack =
                list.OrderBy(x => x.RackName).GroupBy(x => x.RackName).Select(x => x.FirstOrDefault());
            data.RackAvailableCount = listavailablerack.Count();
            var listrack = locations.OrderBy(x => x.RackName).GroupBy(x => x.RackName).Select(x => x.FirstOrDefault());
            data.Racks = listrack.Select(x => new SelectListItem
            {
                Value = x.RackName,
                Text = x.RackName
            }).ToList();

            var listpow = new List<SelectListItem>();
            int[] listp = new int[] {10,11,12,13,14,15,16,17,18,19,20};
            foreach (var i in listp)
            {
                string num = (i).ToString();
                SelectListItem item = new SelectListItem()
                {
                    Value = num,
                    Text = num + "KW"
                };
                listpow.Add(item);
            }
            data.ListPower = listpow;
            data.Locations = locations;
            return View(data);
        }
开发者ID:haltt051093,项目名称:IMS-datacenter,代码行数:32,代码来源:LocationController.cs

示例8: Create

        public ActionResult Create()
        {
            var issueStatues = issueStatus.GetAllIssueStatuses();
            var items = new List<SelectListItem>();

            foreach (var i in issueStatues)
            {
                SelectListItem s = new SelectListItem { Text = i.StatusName, Value = i.Id.ToString() };
                items.Add(s);

            }

            var allAdmins = admin.GetAllAdmins();
            var admins = new List<SelectListItem>();
            foreach (var a in allAdmins)
            {
                SelectListItem currentItem = new SelectListItem { Text = a.UserName, Value = a.Id.ToString() };

                admins.Add(currentItem);
            }

            var reasons = CreateListOfReasons(String.Empty);
            
            ViewBag.IssueStatus = items;
            ViewBag.AssignedTo = admins;
            ViewBag.Reason = reasons;

            return View();
        }
开发者ID:NuGet,项目名称:Entropy,代码行数:29,代码来源:RequestController.cs

示例9: GetDaysForSelectList

        // days
        private List<SelectListItem> GetDaysForSelectList()
        {

           
            List<SelectListItem> daySelectListItems = new List<SelectListItem>();
            SelectListItem itemempty = new SelectListItem();
            itemempty.Text = "Select";
            itemempty.Value = "";
            daySelectListItems.Add(itemempty);
            Dictionary<string, int> days = new Dictionary<string, int>()
            {
                {"SAT",1},
                {"SUN",2},
                {"MON",3},
                {"TUE",4},
                {"WED",5},
                {"THU",6},
                {"FRI",7}
            };
            foreach (var day in days)
            {
                SelectListItem item = new SelectListItem
                {
                    Text = day.Key,
                    Value = day.Value.ToString()
                };
                daySelectListItems.Add(item);
            }
            return daySelectListItems;

        }
开发者ID:mursalinkabir,项目名称:UniversityCourseAndResultManagement,代码行数:32,代码来源:AllocateClassController.cs

示例10: RegUser

        //
        // GET: /Reg/
        public ActionResult RegUser()
        {
            PageView view =new PageView();
            view.PageIndex = 0;
            view.PageSize = 35;
            view.RecordCount = 0;
            JsonFlexiGridData data = Bo.BoFactory.GetSMC_UnitBo.QueryUnitByUnitCode(view, "");

            List<SelectListItem> unitList = new List<SelectListItem>();
            foreach (FlexiGridRow r in data.rows)
            {
                SelectListItem u = new SelectListItem();
                u.Value =r.cell[0];
                u.Text = r.cell[1];
                unitList.Add(u);
            }

            List<SelectListItem> genderList = new List<SelectListItem>();
            genderList.Add(new SelectListItem { Text = "男", Value = "male" });
            genderList.Add(new SelectListItem { Text = "女", Value = "female" });

            ViewData["Unit_ID"] = unitList;
            ViewData["UL_Gender"] = genderList;
            return View();
        }
开发者ID:xiachanghao,项目名称:SmartBoxConsole,代码行数:27,代码来源:RegController.cs

示例11: DisplaySearchResultsViewModel

        // Constructor that excepts search result
        public DisplaySearchResultsViewModel(string searchTerm)
        {
            CoreysListEntities db = new CoreysListEntities();

            // populate properties
            this.SearchTerm = searchTerm; 
            this.Listings = db.Listings.Where(l => l.Headline.Contains(searchTerm)
                || l.Description.Contains(searchTerm)).ToList();

            // instantiate lists of selectlistitems
            List<State> allStates = db.States.ToList();
            States = new List<SelectListItem>();
            Cities = new List<SelectListItem>();

            // assign values to slider filter
            PriceMaxFilter = 100000;
            PriceMinFilter = 0;

            // convert all the states into selectlistitems
            foreach (State s in allStates)
            {
                SelectListItem castState = new SelectListItem();
                castState.Text = s.StateName;
                castState.Value = s.StateID.ToString();
                States.Add(castState);
            }
        }
开发者ID:johansen912,项目名称:CoreysList,代码行数:28,代码来源:DisplaySearchResultsViewModel.cs

示例12: Apply

 public ActionResult Apply()
 {
     ((dynamic) base.ViewBag).Title = "申请达人";
     if (base.CurrentUser == null)
     {
         return base.RedirectToAction("Pioneer", "Star");
     }
     Maticsoft.ViewModel.SNS.Star model = new Maticsoft.ViewModel.SNS.Star();
     List<Maticsoft.Model.SNS.StarType> modelList = this.starTypeBll.GetModelList("");
     List<SelectListItem> list2 = new List<SelectListItem>();
     SelectListItem item2 = new SelectListItem {
         Value = "0",
         Text = "请选择"
     };
     list2.Add(item2);
     if ((modelList != null) && (modelList.Count > 0))
     {
         foreach (Maticsoft.Model.SNS.StarType type in modelList)
         {
             SelectListItem item = new SelectListItem {
                 Value = type.TypeID.ToString(),
                 Text = type.TypeName
             };
             list2.Add(item);
         }
     }
     model.DropList = list2;
     return base.View(model);
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:29,代码来源:StarController.cs

示例13: EditFunction

 public ActionResult EditFunction(SelectListItem functionWithComment)
 {
     if (functionWithComment == null) return View();
     PerformerStatFilteredViewModel.AddFunction(functionWithComment.Text, functionWithComment.Value);
     // перенаправить на страницу отчета
     return RedirectToAction("TraderRate");
 }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:7,代码来源:BrokerReportController.cs

示例14: WithExpressionSelectListAndAttributeExpressionReturnsCorrectly

        public void WithExpressionSelectListAndAttributeExpressionReturnsCorrectly()
        {
            string attributeName = "AttributeName";
            string attributeValue = "AttributeValue";
            string selectListItemText = "Text1";
            string selectListItemValue = "Value1";

            SelectListItem[] selectList = new SelectListItem[]
            {
                new SelectListItem()
                    {
                        Text = selectListItemText,
                        Value = selectListItemValue
                    }
            };

            var viewModel = new DropDownListViewModel();

            HtmlHelper<DropDownListViewModel> htmlHelper = HtmlHelperGenerator.CreateHtmlHelper( viewModel );

            var result = htmlHelper.DropDownListFor( x => x.SelectedValue, selectList, x => x.Attribute( attributeName, attributeValue ) );

            string expectedResult = string.Format( "<select {0}=\"{1}\" id=\"SelectedValue\" name=\"SelectedValue\"><option value=\"{2}\">{3}</option>\r\n</select>", attributeName, attributeValue, selectListItemValue, selectListItemText );
            Assert.AreEqual( expectedResult, result.ToHtmlString() );
        }
开发者ID:john-t-white,项目名称:Hex,代码行数:25,代码来源:DropDownListExtensions_DropDownListFor.cs

示例15: Create

        //
        // GET: /Tasks/Create
        public ActionResult Create(int id, System.Nullable<int> devId)
        {
            var db = new BurnDown.Models.DB();
            var developers = db.developers;

            IList<SelectListItem> devList = new List<SelectListItem>();

            foreach (BurnDown.Models.developer dev in developers)
            {
                SelectListItem DevItem = new SelectListItem();
                DevItem.Text = dev.firstName + " " + dev.lastName;
                DevItem.Value = dev.developerId.ToString();
                devList.Add(DevItem);
                if (devId == dev.developerId) DevItem.Selected = true;
                DevItem = null;
            }
            ViewData["ddList"] = devList;

            var projects = db.projects;

            IList<SelectListItem> projList = new List<SelectListItem>();

            foreach (BurnDown.Models.project proj in projects)
            {
                SelectListItem ProjItem = new SelectListItem();
                ProjItem.Text = proj.projectName;
                ProjItem.Value = proj.projectId.ToString();
                projList.Add(ProjItem);
                if (id == proj.projectId) ProjItem.Selected = true;
                ProjItem = null;

            }
            ViewData["projDDList"] = projList;
            return View();
        }
开发者ID:gindyo,项目名称:burn_down,代码行数:37,代码来源:TasksController.cs


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