public List<SelectListItem> GetAvailableLayouts(int siteId) { List<SelectListItem> layouts = new List<SelectListItem>(); string pathToViews = GetPathToViews(); DirectoryInfo directoryInfo = new DirectoryInfo(pathToViews); string filterPattern = string.Format(options.BrowseFilterFormat, siteId.ToString()); FileInfo[] files = directoryInfo.GetFiles(filterPattern); foreach(FileInfo f in files) { SelectListItem layout = new SelectListItem { Text = layoutDisplayFilter.FilterDisplayName(siteId,f.Name), Value = f.Name }; layouts.Add(layout); } if(layouts.Count == 0) { layouts.Add(new SelectListItem { Text = layoutDisplayFilter.FilterDisplayName(siteId, options.DefaultLayout), Value = options.DefaultLayout }); } return layouts; }
private List <SelectListItem> GetDeviceList(string selectectValue) { List <SelectListItem> l = new List <SelectListItem>(); l.Add(new Microsoft.AspNet.Mvc.Rendering.SelectListItem() { Text = "" }); myHub.hubConfig?.device.ForEach(x => { var sli = new Microsoft.AspNet.Mvc.Rendering.SelectListItem() { Text = x.label, Selected = (x.label == selectectValue) }; l.Add(sli); }); return(l); }
public async Task<IActionResult> Edit(int? id) { if (id == null) { return new BadRequestResult(); } var pers = await this.dbContext.Set<Person>().Include(f => f.PersonPhotos).FirstAsync(p => p.Id == id); if (pers == null) { return this.HttpNotFound(); } var allFotos = this.dbContext.Set<Photo>().ToList(); var personFotos = (from r in allFotos where pers.PersonPhotos.Any(ap => ap.PhotoId.Equals(r.Id)) select r).ToList(); var model = new PersonViewModel() { Id = pers.Id, Name = pers.Name }; // load the Photos for selection in the form: foreach (var foto in allFotos) { var listItem = new SelectListItem() { Text = foto.Name, Value = foto.Id.ToString(), Selected = personFotos.Any(g => g.Id == foto.Id) }; model.PhotosList.Add(listItem); } return this.View(model); }
public void CreateStateList() { List<State> listOfStates = new List<State> { new State() {Name = "Arkansas", Abbreviation = "AR"}, new State() {Name = "Kansas", Abbreviation = "KS" }, new State() {Name = "Illinois", Abbreviation = "IL" }, new State() {Name = "Texas", Abbreviation = "TX" }, new State() {Name = "Washington", Abbreviation = "WA"} }; states = new List<SelectListItem>(); foreach (State state in listOfStates) { SelectListItem newItem = new SelectListItem(); newItem.Text = state.Abbreviation; newItem.Value = state.Name; states.Add(newItem); } }
/// <remarks> /// Not used directly in HtmlHelper. Exposed for use in DefaultDisplayTemplates. /// </remarks> internal static TagBuilder GenerateOption(SelectListItem item, string encodedText) { var tagBuilder = new TagBuilder("option") { InnerHtml = encodedText, }; if (item.Value != null) { tagBuilder.Attributes["value"] = item.Value; } if (item.Selected) { tagBuilder.Attributes["selected"] = "selected"; } if (item.Disabled) { tagBuilder.Attributes["disabled"] = "disabled"; } return(tagBuilder); }
protected override IEnumerable<SelectListItem> GetEnumSelectList(ModelMetadata metadata) { Metadata = metadata; SelectListItems = base.GetEnumSelectList(metadata); if (SelectListItems != null) { // Perform a deep copy to help confirm the mutable items are not changed. var copiedSelectListItems = new List<SelectListItem>(); CopiedSelectListItems = copiedSelectListItems; foreach (var item in SelectListItems) { var copy = new SelectListItem { Disabled = item.Disabled, Group = item.Group, Selected = item.Selected, Text = item.Text, Value = item.Value, }; copiedSelectListItems.Add(copy); } } return SelectListItems; }
private static IWriter2<SelectOption, AnyContent> SelectListItemToSelectOption(IBootstrapContext context, SelectListItem item) { return context.CreateWriter<SelectOption, AnyContent>().Value(item.Value).Disabled(item.Disabled).Content(item.Text); }
private void AgregarDropDowns(CursoViewModel modelo) { List<SelectListItem> categorias = new List<SelectListItem>(); SelectListItem categoria = new SelectListItem(); //Creamos un DropDown para elegir categoria. foreach (var item in _gestionDeCursos.ObtenerCategorias()) { categoria = new SelectListItem { Text = item.Descripcion, Value = item.CategoriaId.ToString() }; categorias.Add(categoria); } modelo.Categorias = categorias; List<SelectListItem> profesores = new List<SelectListItem>(); SelectListItem profesor = new SelectListItem(); //Creamos un DropDown para elegir "Profesor" var usuario = User; foreach (var item in _gestionDeUsuarios.ObtenerProfesores()) { profesor = new SelectListItem { Text = item.NombreDeUsuario, Value = item.UsuarioId.ToString() }; profesores.Add(profesor); } modelo.Usuarios = profesores; }
// GET: TestRunnerGroups public IActionResult Index() { ViewData["Message"] = HttpContext.Session.GetString("Message"); HttpContext.Session.Remove("Message"); var trg = new TestRunnerGroupsAndNewTestRunnerGroupAndProjectsAndFoldersAndGroupsAndRuns(); trg.TestRunnerGroups = _context.TestRunnerGroup; trg.TestRunnerGroup = new TestRunnerGroup(); trg.Projects = _context.Project; trg.Folders = _context.Folder; trg.Groups = _context.Group; trg.Runs = _context.Run; var BlankSelectListItem = new SelectListItem { Text = "", Value = null }; var projects = new SelectList(_context.Project, "ID", "Name").ToList(); projects.Insert(0, BlankSelectListItem); ViewBag.Projects = projects; var folders = new SelectList(_context.Folder, "FolderID", "Name").ToList(); folders.Insert(0, BlankSelectListItem); ViewBag.Folders = folders; var groups = new SelectList(_context.Group, "GroupID", "Name").ToList(); groups.Insert(0, BlankSelectListItem); ViewBag.Groups = groups; var runs = new SelectList(_context.Run, "RunID", "Name").ToList(); runs.Insert(0, BlankSelectListItem); ViewBag.Runs = runs; return View(trg); }
// GET: DependencyGroups/Details/5 public IActionResult Details(int? id) { ViewData["Message"] = HttpContext.Session.GetString("Message"); HttpContext.Session.Remove("Message"); if (id == null) { return HttpNotFound(); } DependencyGroupAndNewDependency dependencyGroupAndNewDependency = new DependencyGroupAndNewDependency(); dependencyGroupAndNewDependency.DependencyGroup = _context.DependencyGroup.Single(m => m.DependencyGroupID == id); if (dependencyGroupAndNewDependency.DependencyGroup == null) { return HttpNotFound(); } dependencyGroupAndNewDependency.DependencyGroup.Dependencies = _context.Dependency.Where(t => t.DependencyGroupID == id).ToList(); foreach (var dpg in dependencyGroupAndNewDependency.DependencyGroup.Dependencies) { dpg.TestRun = _context.TestRun.SingleOrDefault(t => t.TestRunID == dpg.TestRunID); dpg.TestRun.Test = _context.Test.SingleOrDefault(t => t.TestID == dpg.TestRun.TestID); } ViewData["DependencyGroupID"] = id; var TestRuns = new List<SelectListItem>(); foreach(var testRun in _context.TestRun) { var testName = _context.Test.SingleOrDefault(t => t.TestID == testRun.TestID).Name; var runName = _context.Run.SingleOrDefault(t => t.RunID == testRun.RunID).Name; var text = runName + "=>" + testName + "=>" + testRun.TestRunID.ToString(); var SelectListItem = new SelectListItem() { Value = testRun.TestRunID.ToString(), Text = text }; TestRuns.Add(SelectListItem); } ViewBag.TestRuns = new SelectList(TestRuns, "Value", "Text"); ViewBag.browsers = new SelectList(new List<string> { "Chrome", "Firefox", "IE" }); return View(dependencyGroupAndNewDependency); }
private SelectList GetDays() { var res = new List<SelectListItem>(); foreach( var d in Enum.GetValues(typeof(WeekDaysEnum))) { var si = new SelectListItem() { Value = ( (int)d).ToString(), //ID = (int)d, Text = d.ToString() //Name = d.ToString() }; res.Add(si); } var enumData = from DayOfWeek d in Enum.GetValues(typeof(WeekDaysEnum)) select new { ID = (int)d, Name = d.ToString() }; //return new SelectList(enumData, "ID", "Name"); return new SelectList(res, "Value", "Text"); }
internal static string GenerateOption(SelectListItem item, string encodedText) { var builder = new TagBuilder("option") { InnerHtml = encodedText, }; if (item.Value != null) { builder.Attributes["value"] = item.Value; } if (item.Selected) { builder.Attributes["selected"] = "selected"; } if (item.Disabled) { builder.Attributes["disabled"] = "disabled"; } return builder.ToString(TagRenderMode.Normal); }
private string GenerateOption(SelectListItem item) { var encodedText = Encode(item.Text); return GenerateOption(item, encodedText); }