• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mvc.SelectListItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DurationEditor

        public static IHtmlString DurationEditor(this HtmlHelper<TimeSpan> html,
		                                         TimeSpan currentValue,
		                                         object htmlAttributes = null)
        {
            var htmlAttibutesDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            var currentValueParsed = TimeSpanFormatter.Format(currentValue).Split(' ');
            var value              = currentValueParsed[0];
            var currentUnit        = currentValueParsed[1];

            var availableUnits = new SelectListItem[]
            {
                new SelectListItem { Text = Lang.TimeSpan_Days,    Value = DurationUnit.Days.ToString() },
                new SelectListItem { Text = Lang.TimeSpan_Hours,   Value = DurationUnit.Hours.ToString() },
                new SelectListItem { Text = Lang.TimeSpan_Minutes, Value = DurationUnit.Minutes.ToString() },
            };

            foreach(var unit in availableUnits)
            {
                unit.Selected = (unit.Text == currentUnit);
            }

            var textbox  = html.NumberInput(String.Empty, value: value, min: 1, cssClass: "value");
            var dropdown = html.DropDownList("Unit", availableUnits, htmlAttributes: new { @class = "unit" });

            var div = new TagBuilder("div");
            div.MergeAttributes(htmlAttibutesDictionary);
            div.AddCssClass("duration-editor");
            div.InnerHtml = textbox.ToHtmlString() + dropdown.ToHtmlString();

            return new HtmlString(div.ToString());
        }
开发者ID:Strachu,项目名称:Auctioneer,代码行数:32,代码来源:DurationEditor.cs


示例17: AddPlayerModalVM

        public AddPlayerModalVM(List<Team> teamsList, List<Position> positionsList)
        {
            Teams = new List<SelectListItem>();

            foreach (var team in teamsList)
            {
                var st = new SelectListItem();

                st.Text = team.TeamName;
                st.Value = team.TeamID.ToString();

                Teams.Add(st);
            }

            PrimaryPositions = new List<SelectListItem>();
            SecondaryPositions = new List<SelectListItem>();

            foreach (var position in positionsList)
            {
                var sp = new SelectListItem();

                sp.Text = position.PositionName;
                sp.Value = position.PositionID.ToString();

                PrimaryPositions.Add(sp);
                SecondaryPositions.Add(sp);
            }
        }
开发者ID:anti0xidant,项目名称:BaseballLeague,代码行数:28,代码来源:AddPlayerModalVM.cs


示例18: ListaGradosPaDropSelect

        /// <summary>
        /// Lista de Grados_Proximidad para un dropdownlist selected value
        /// </summary>
        /// <returns></returns>
        public List<SelectListItem> ListaGradosPaDropSelect(string id)
        {     
            List<SelectListItem> l_AFR = new List<SelectListItem>();

            for (int i = 0; i <= 2;i++ ) {

                SelectListItem item = new SelectListItem();
                if (i == int.Parse(id))
                {

                    item.Value = i.ToString();
                    item.Text = i.ToString();
                    item.Selected = true;
                }
                else
                {
                    item.Value = i.ToString();
                    item.Text = i.ToString();
                }

                l_AFR.Add(item);            
            
            }
            return l_AFR;
        }
开发者ID:heinerabella,项目名称:REDELECTRICA,代码行数:29,代码来源:Patologias.cs


示例19: Create

        // GET: BudgetItems/Create
        public ActionResult Create(int householdId, int budgetId)
        {
            //1) get default categories from database
            var categories = db.Categories.Where(x => x.IsDefault == true).OrderBy(x => x.CategoryName).ToList();

            //2) get all custom categories
            var household = db.Households.FirstOrDefault(x => x.Id == householdId);
            var householdcategories = household.Categories.ToList();

            //3) add custom categories for household to main household list

            foreach (Category c in householdcategories)
            {
                categories.Add(c);
            }

            List<SelectListItem> categoriesDropdown = new List<SelectListItem>();

            foreach (Category c in categories)
            {
                SelectListItem item = new SelectListItem
                {
                    Text = c.CategoryName,
                    Value = c.Id.ToString()
                };

                categoriesDropdown.Add(item);
            }
            ViewBag.BudgetId = budgetId;
            ViewBag.CategoryId = categoriesDropdown;
            TempData["householdId"] = householdId;

            return View();
        }
开发者ID:evtolley,项目名称:CashCache,代码行数:35,代码来源:BudgetItemsController.cs


示例20: CSPFViewModel

        /// <summary>
        /// Constructor para inicializar la plantilla con el ID de un proyecto específico
        /// </summary>
        /// <param name="idProyecto"></param>
        public CSPFViewModel(int idProyecto)
        {
            this.idProyecto = idProyecto;
            this.proyectoActual = new Proyecto(idProyecto);
            this.listaNodos = new List<SelectListItem>();

            foreach (var nodo in this.proyectoActual.listadoRouters)
            {
                SelectListItem temp = new SelectListItem();
                temp.Value = nodo.idRouter.ToString();
                string tempHostname = nodo.cHostname != null ? nodo.cHostname.Trim() : String.Empty;
                string tempIpAdress = nodo.cRouterID != null ? "[" + nodo.cRouterID.Trim() + "]" : String.Empty;

                temp.Text = tempHostname + " " + tempIpAdress;
                listaNodos.Add(temp);
            }

            List<Afinidad> listaAfinidades = Afinidad.SelectListaAfinidades(this.idProyecto);
            this.listaAfinidades = Afinidad.ConvertDropdownListaAfinidades(listaAfinidades);

            this.calculatedPath = new List<NodoDijkstra>();
            this.cRutaHostnames = "";
            this.listaEnlacesPath = new List<Enlace>();
            this.saveDijkstra = "false";
        }
开发者ID:diodax,项目名称:ProyectoMPLS,代码行数:29,代码来源:CSPFViewModel.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.UrlHelper类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.SelectList类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap