public void Constructor3SetsProperties_Value_Text() { // Arrange IEnumerable items = new object[0]; // Act SelectList selectList = new SelectList(items, "SomeValueField", "SomeTextField"); // Assert Assert.Same(items, selectList.Items); Assert.Equal("SomeValueField", selectList.DataValueField); Assert.Equal("SomeTextField", selectList.DataTextField); Assert.Null(selectList.SelectedValues); Assert.Null(selectList.SelectedValue); }
public void Constructor_SetsProperties_Items_Value_Text_SelectedValue_DisabledValues_Group() { // Arrange IEnumerable items = new[] { new { Value = "A", Text = "Alice", Group = "AB" }, new { Value = "B", Text = "Bravo", Group = "AB" }, new { Value = "C", Text = "Charlie", Group = "C" }, }; object selectedValue = "A"; IEnumerable disabledValues = new[] { "A", "C" }; // Act SelectList selectList = new SelectList(items, "Value", "Text", "Group", selectedValue, disabledValues); List<object> selectedValues = selectList.SelectedValues.Cast<object>().ToList(); // Assert Assert.Same(items, selectList.Items); Assert.Equal("Value", selectList.DataValueField); Assert.Equal("Text", selectList.DataTextField); Assert.Same(selectedValue, selectList.SelectedValue); Assert.Single(selectedValues); Assert.Same(selectedValue, selectedValues[0]); Assert.Equal("Group", selectList.DataGroupField); Assert.Same(disabledValues, selectList.DisabledValues); }
public void Constructor3SetsProperties_SelectedValue_DisabledValues() { // Arrange IEnumerable items = new[] { "A", "B", "C" }; IEnumerable selectedValues = "A"; IEnumerable disabledValues = new[] { "B", "C" }; // Act SelectList multiSelect = new SelectList(items, selectedValues, disabledValues); // Assert Assert.Same(items, multiSelect.Items); Assert.Equal(new object[] { selectedValues }, multiSelect.SelectedValues); Assert.Equal(disabledValues, multiSelect.DisabledValues); Assert.Null(multiSelect.DataTextField); Assert.Null(multiSelect.DataValueField); }
private static ViewDataDictionary GetViewDataWithSelectList() { ViewDataDictionary viewData = new ViewDataDictionary(); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); viewData["foo"] = selectList; viewData["foo.bar"] = selectList; return viewData; }
public void DropDownListUsesViewDataDefaultValue() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(_dropDownListViewData); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), "Charlie"); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */); // Assert Assert.Equal( "<select id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public void DropDownListUsesExplicitValueIfNotProvidedInViewData() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */); // Assert Assert.Equal( "<select id=\"foo\" name=\"foo\"><option value=\"A\">Alpha</option>" + Environment.NewLine + "<option value=\"B\">Bravo</option>" + Environment.NewLine + "<option selected=\"selected\" value=\"C\">Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public void Constructor2SetsProperties_Items_SelectedValue() { // Arrange IEnumerable items = new object[0]; object selectedValue = new object(); // Act SelectList selectList = new SelectList(items, selectedValue); List<object> selectedValues = selectList.SelectedValues.Cast<object>().ToList(); // Assert Assert.Same(items, selectList.Items); Assert.Null(selectList.DataValueField); Assert.Null(selectList.DataTextField); Assert.Same(selectedValue, selectList.SelectedValue); Assert.Single(selectedValues); Assert.Same(selectedValue, selectedValues[0]); }
public void DropDownListUsesExplicitValueIfNotProvidedInViewData_Unobtrusive() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); helper.ViewContext.ClientValidationEnabled = true; helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; helper.ViewContext.FormContext = new FormContext(); helper.ClientValidationRuleFactory = (name, metadata) => new[] { new ModelClientValidationRule { ValidationType = "type", ErrorMessage = "error" } }; SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, (string)null /* optionLabel */); // Assert Assert.Equal( "<select data-val=\"true\" data-val-type=\"error\" id=\"foo\" name=\"foo\"><option value=\"A\">Alpha</option>" + Environment.NewLine + "<option value=\"B\">Bravo</option>" + Environment.NewLine + "<option selected=\"selected\" value=\"C\">Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// GET: DepartamentValuationFacts/Create public IActionResult Create() { ViewData["DepartamentId"] = new SelectList(_context.Departaments, "Id", "FullName"); return(View()); }
public void Start(QueryType type, SelectList list, string expression, DateTime start, DateTime end) { if (type == QueryType.Select) { _query.Append("SELECT "); } switch (list) { case SelectList.All: _query.Append("*"); break; case SelectList.Count: _query.Append("Count(*) AS C"); break; case SelectList.Expression: _query.Append(expression); break; } _query.Append(" "); _start = start; _end = end; }
private void WriteSelected(SelectList selectList) { foreach (var option in selectList.Options) { Console.Write(option.Selected + ", "); var nativeElement = (IEElement)option.NativeElement; var htmlOptionElement = (mshtml.IHTMLOptionElement)nativeElement.AsHtmlElement; Console.WriteLine(htmlOptionElement.selected); } Console.WriteLine("----"); }
public async Task <IActionResult> NovoProduto() { ViewData["CategoriaId"] = new SelectList(await _contexto.Categorias.ToListAsync(), "CategoriaId", "Nome"); return(View()); }
public void DropDownListForWithPrefixAndEmptyName() { // Arrange HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooModel>()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; // Act MvcHtmlString html = helper.DropDownListFor(m => m, selectList, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( @"<select baz=""BazObjValue"" id=""MyPrefix"" name=""MyPrefix""><option>Alpha</option> <option>Bravo</option> <option>Charlie</option> </select>", html.ToHtmlString()); }
public void SelectHelpersUseCurrentCultureToConvertValues() { // Arrange HtmlHelper defaultValueHelper = MvcHelper.GetHtmlHelper(new ViewDataDictionary { { "foo", new[] { new DateTime(1900, 1, 1, 0, 0, 1) } }, { "bar", new DateTime(1900, 1, 1, 0, 0, 1) } }); HtmlHelper helper = MvcHelper.GetHtmlHelper(); SelectList selectList = new SelectList(GetSampleCultureAnonymousObjects(), "Date", "FullWord", new DateTime(1900, 1, 1, 0, 0, 0)); var tests = new[] { // DropDownList(name, selectList, optionLabel) new { Html = "<select id=\"foo\" name=\"foo\"><option selected=\"selected\" value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine + "</select>", Action = new Func<MvcHtmlString>(() => helper.DropDownList("foo", selectList, (string)null)) }, // DropDownList(name, selectList, optionLabel) (With default value selected from ViewData) new { Html = "<select id=\"bar\" name=\"bar\"><option value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine + "<option selected=\"selected\" value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine + "</select>", Action = new Func<MvcHtmlString>(() => defaultValueHelper.DropDownList("bar", selectList, (string)null)) }, // ListBox(name, selectList) new { Html = "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option selected=\"selected\" value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine + "</select>", Action = new Func<MvcHtmlString>(() => helper.ListBox("foo", selectList)) }, // ListBox(name, selectList) (With default value selected from ViewData) new { Html = "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option value=\"01/01/1900 00:00:00\">Alpha</option>" + Environment.NewLine + "<option selected=\"selected\" value=\"01/01/1900 00:00:01\">Bravo</option>" + Environment.NewLine + "<option value=\"01/01/1900 00:00:02\">Charlie</option>" + Environment.NewLine + "</select>", Action = new Func<MvcHtmlString>(() => defaultValueHelper.ListBox("foo", selectList)) } }; // Act && Assert foreach (var test in tests) { Assert.Equal(test.Html, test.Action().ToHtmlString()); } }
// GET: Purchases/Create public IActionResult Create() { ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Firstname"); return(View()); }
// GET: Products/Create public IActionResult Create() { ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Description"); return(View()); }
public async Task<IActionResult> CreateAccount([Bind("Person", "Address", "Photo", "Learner", "Cv")] LearnerViewModel learnerViewModel) { if (ModelState.IsValid) { // This Uploads learner profile image var photoPath = _fconfig.Images + learnerViewModel.Person.NationalId + "/" + Utils.GenerateImageFolderId() + "/"; if (learnerViewModel.Photo != null) { _fileService.UploadFile( learnerViewModel.Photo,_env.WebRootPath + photoPath); learnerViewModel.Person.PhotoName = learnerViewModel.Photo.FileName; learnerViewModel.Person.PhotoPath = photoPath; Console.WriteLine(" FILE NAME : " + learnerViewModel.Photo.FileName); } var cvPath = _fconfig.Documents + learnerViewModel.Person.NationalId + "/" + Utils.GenerateDocsFolderId() + "/"; if (learnerViewModel.Cv != null) { _fileService.UploadFile( learnerViewModel.Cv,_env.WebRootPath + cvPath); learnerViewModel.Person.CvName = learnerViewModel.Cv.FileName; learnerViewModel.Person.CvPath = cvPath; Console.WriteLine(" FILE NAME : " + learnerViewModel.Cv.FileName); } learnerViewModel.Person.CreatedBy = "admin"; learnerViewModel.Person.DateCreated = DateTime.Now; learnerViewModel.Person.LastUpdatedBy = "admin"; learnerViewModel.Person.DateUpdated = DateTime.Now; learnerViewModel.Address.CreatedBy = "admin"; learnerViewModel.Address.DateCreated = DateTime.Now; learnerViewModel.Address.LastUpdatedBy = "admin"; learnerViewModel.Address.DateUpdated = DateTime.Now; learnerViewModel.Learner.CreatedBy = "admin"; learnerViewModel.Learner.DateCreated = DateTime.Now; learnerViewModel.Learner.LastUpdatedBy = "admin"; learnerViewModel.Address.DateUpdated = DateTime.Now; learnerViewModel.Learner.AppliedYn = Const.FALSE; learnerViewModel.Learner.RecruitedYn = Const.FALSE; //Link the Address to the Person learnerViewModel.Person.Address.Add(learnerViewModel.Address); // Add the Person into the Database var user = await _lookUpService.GetUserByUsrname(User.Identity.Name); learnerViewModel.Person.UserId = user.Id; learnerViewModel.Person.Email = user.Email; //Now link the learner to this Person Profile created learnerViewModel.Learner.Person = learnerViewModel.Person; //Then Add the Company //Then Add the Learner to the Database _context.Add(learnerViewModel.Learner); //Save the Person and Address in to the Database await _context.SaveChangesAsync(); _notyf.Warning("Profile created successful...", 5); ViewData["CitizenshipStatusId"] = new SelectList(_context.CitizenshipStatus, "CitizenshipStatusId", "CitizenshipStatusDesc",learnerViewModel.Person.CitizenshipStatusId); ViewData["DisabilityStatusId"] = new SelectList(_context.DisabilityStatus, "DisabilityStatusId", "DisabilityStatusDesc",learnerViewModel.Person.DisabilityStatusId); ViewData["EquityId"] = new SelectList(_context.Equity, "EquityId", "EquityDesc",learnerViewModel.Person.EquityId); ViewData["GenderId"] = new SelectList(_context.Gender, "GenderId", "GenderDesc",learnerViewModel.Person.GenderId); ViewData["HomeLanguageId"] = new SelectList(_context.HomeLanguage, "HomeLanguageId", "HomeLanguageDesc",learnerViewModel.Person.HomeLanguageId); ViewData["NationalityId"] = new SelectList(_context.Nationality, "NationalityId", "NationalityDesc",learnerViewModel.Person.NationalityId); ViewData["SuburbId"] = new SelectList(_lookUpService.GetSuburbs().Result, "id", "name",learnerViewModel.Address.SuburbId); ViewData["CityId"] = new SelectList(await _lookUpService.GetCities(), "id", "name",learnerViewModel.Address.CityId); ViewData["ProvinceId"] = new SelectList(_lookUpService.GetProvinces().Result, "id", "name",learnerViewModel.Address.ProvinceId); ViewData["CountryId"] = new SelectList(_lookUpService.GetCountries().Result, "id", "name",learnerViewModel.Address.CountryId); ViewData["AddressTypeId"] = new SelectList(_lookUpService.GetAddressTypes().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId); /*ViewData["InstitutionId"] = new SelectList(_lookUpService.GetInstitutions().Result, "id", "name",learnerViewModel.Learner.); ViewData["CourseId"] = new SelectList(_lookUpService.GetCourses().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId);*/ ViewData["SchoolId"] = new SelectList(_lookUpService.GetSchools().Result, "id", "name",learnerViewModel.Learner.SchoolId); ViewData["SchoolGradeId"] = new SelectList(_lookUpService.GetSchoolGrades().Result, "id", "name",learnerViewModel.Learner.SchoolGradeId); return RedirectToAction(nameof(Details), new { id = learnerViewModel.Person.NationalId }); } return View(); }
// GET: Alumno/Create public IActionResult Create() { ViewData["CursoId"] = new SelectList(_context.Cursos, "Id", "Id"); return(View()); }
public ManageProblemObserved() { CategoryList = new SelectList(Enumerable.Empty <SelectListItem>()); SubCategoryList = new SelectList(Enumerable.Empty <SelectListItem>()); }
// GET: EmergenciaInstitucion/Create public IActionResult Create() { ViewData["EmergenciaId"] = new SelectList(_context.Emergencia, "EmergenciaId", "Descripcion"); ViewData["InstitucionPublicaId"] = new SelectList(_context.InstitucionPublica, "InstitucionPublicaId", "Estado"); return(View()); }
// GET: Contracts/Create public IActionResult Create() { ViewData["UnitID"] = new SelectList(_context.Units, "UnitID", "UnitID"); ViewData["UserID"] = new SelectList(_context.Users, "UserID", "UserID"); return(View()); }
// GET: Accounts/Create public IActionResult Create() { ViewData["RoleID"] = new SelectList(_context.Roles, "ID", "ID"); return(View()); }
// GET: Accidents/Create public IActionResult Create() { ViewData["LabDayId"] = new SelectList(_context.LabDay, "ID", "ID"); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id"); return(View()); }
// GET: Gatherings/Create public IActionResult Create() { ViewData["LocationId"] = new SelectList(_context.Location, "LocationId", "County"); ViewData["UserId"] = new SelectList(_context.User, "Id", "Id"); return(View()); }
public void ListBoxForUsesLambdaDefaultValue() { // Arrange FooArrayModel model = new FooArrayModel { foo = new[] { "Bravo" } }; HtmlHelper<FooArrayModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooArrayModel>(model)); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.ListBoxFor(m => m.foo, selectList); // Assert Assert.Equal( "<select id=\"foo\" multiple=\"multiple\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public ActionResult Registrar(Animal a, HttpPostedFileBase archivo) { string msg; SelectList cboRaza = new SelectList(r_bl.lista(a.TIPO), "CODRAZA", "DESC_RAZA", a.RAZA); //SelectList cboRaza = new SelectList(bd.RAZAANIMAL.Where(x => x.CODTIPO == a.TIPO).OrderBy(x => x.DESC_RAZA).ToList(), "CODRAZA", "DESC_RAZA", a.RAZAANIMAL); if (ModelState.IsValid == false) { ViewBag.razas = cboRaza; return(View(a)); } if (a.EDAD == null) { a.EDAD = 0; } if (a.PESO == null) { a.PESO = 0; } if (a.DESCRIPCION == null) { a.DESCRIPCION = ""; } if (archivo == null) { a.FOTO = "-"; msg = a_bl.registrar(a); } else { bool p = Path.GetExtension(archivo.FileName) == ".jpg"; bool q = Path.GetExtension(archivo.FileName) == ".png"; bool r = Path.GetExtension(archivo.FileName) == ".gif"; //si el archivo no es jpg, png o gif if (!p && !q && !r) { ViewBag.ext_invalida = "Debe seleccionar una imagen en formato jpg,png o gif"; ViewBag.razas = cboRaza; return(View(a)); } try { string foto = nombreimg(a_bl.cod_autogenerado()) + Path.GetExtension(archivo.FileName); archivo.SaveAs(Server.MapPath("~/imagenes/animales/" + foto)); a.FOTO = foto; msg = a_bl.registrar(a); } catch (Exception e) { msg = "Error: " + e.Message; } } ViewBag.razas = cboRaza; return(RedirectToAction("ConfirmarOperacion", "Confirmacion", new { mensaje = msg })); }
public void DropDownListWithObjectDictionaryAndTitle() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, "[Select Something]", HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( "<select baz=\"BazObjValue\" id=\"foo\" name=\"foo\"><option value=\"\">[Select Something]</option>" + Environment.NewLine + "<option>Alpha</option>" + Environment.NewLine + "<option>Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// GET: Products/Create public IActionResult Create() { ViewData["IdCreator"] = new SelectList(_context.Creators, "Id", "Id"); ViewData["IdTypeProduct"] = new SelectList(_context.TypeProducts, "Id", "Id"); return(View()); }
// GET: Routes/Create public IActionResult Create() { ViewData["DropOffID"] = new SelectList(stationRepo.GetAll(), "ID", "tostringProp"); ViewData["PickUpID"] = new SelectList(stationRepo.GetAll(), "ID", "tostringProp"); return(View()); }
// GET: Designations/Create public IActionResult Create() { ViewData["DepartmentId"] = new SelectList(departmentRepository.GetDepartmentList(), "Id", "Name"); return(View()); }
public void DropDownListUsesViewDataDefaultValueNoOptionLabel() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(_dropDownListViewData); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), "Charlie"); // Act MvcHtmlString html = helper.DropDownList("foo", selectList); // Assert Assert.Equal( @"<select id=""foo"" name=""foo""><option>Alpha</option> <option selected=""selected"">Bravo</option> <option>Charlie</option> </select>", html.ToHtmlString()); }
public void OnGet(string dep, string voo, string st) { if (!autenticar(2)) { return; } if (!string.IsNullOrEmpty(st)) { int a; int.TryParse(st, out a); resposta = commands["ALTERAR"].execute(new Status() { ID = a }).Entidades; } if (!string.IsNullOrEmpty(dep)) { this.dep = dep; HttpContext.Session.Setstring("dep", dep); int a; int.TryParse(dep, out a); go = getMotivos(a); if (!string.IsNullOrEmpty(voo)) { this.voo = voo; HttpContext.Session.Setstring("voo", voo); int b; int.TryParse(voo, out b); resposta = commands["CONSULTAR"].execute(new Status() { Atual = new Departamento() { ID = a }, Passageiro = new Bilhete() { passagem = new Viagem() { Voo = new Passagens() { ID = b } } } }).Entidades; } else { resposta = commands["CONSULTAR"].execute(new Status() { Atual = new Departamento() { ID = a } }).Entidades; } if (resposta.Count > 0) { nome_dep = ((Status)resposta.ElementAt(0)).Atual.Nome; } } else if (!string.IsNullOrEmpty(voo)) { this.voo = voo; HttpContext.Session.Setstring("voo", voo); int a; int.TryParse(voo, out a); resposta = commands["CONSULTAR"].execute(new Status() { Passageiro = new Bilhete() { passagem = new Viagem() { Voo = new Passagens() { ID = a } } } }).Entidades; } else { resposta = getStatus(); } }
public DropDownListWrapper(SelectList dropDownList, string howFound) : base(howFound) { _dropDownList = dropDownList; }
// GET: Courses/Create public IActionResult Create() { ViewData["DepartmentID"] = new SelectList(_context.Departments, "DepartmentID", "DepartmentID"); return(View()); }
private static void CreateUser(ActiveEventArgs e) { SelectList list = new SelectList {CssClass = "smallSelectList"}; // Adding first static item... ListItem top = new ListItem(Language.Instance["ChooseUser", null, "Choose User..."], "0"); list.Items.Add(top); string curValue = e.Params["Value"].Get<string>(); foreach (User idxUser in ActiveType<User>.Select()) { ListItem i = new ListItem(idxUser.Username, idxUser.Username); list.Items.Add(i); if (curValue == idxUser.Username) { i.Selected = true; } } list.SelectedIndexChanged += delegate(object sender, EventArgs e2) { SelectList lst = sender as SelectList; if (lst == null) return; string[] xtra = lst.Xtra.Split('|'); int rowId = int.Parse(xtra[0]); Whiteboard.Row row = ActiveType<Whiteboard.Row>.SelectByID(rowId); Whiteboard.Cell cell = row.Cells.Find( delegate(Whiteboard.Cell idx) { return idx.Column.Caption == xtra[1]; }); cell.Value = lst.SelectedItem.Value; cell.Save(); UpdateGridValue(e.Params["DataSource"].Value as Node, xtra[0], xtra[1], cell.Value); }; // Sending back our Control e.Params["Control"].Value = list; }
public void DropDownListForWithEnumerableModel_Unobtrusive() { // Arrange HtmlHelper<IEnumerable<RequiredModel>> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<IEnumerable<RequiredModel>>()); helper.ViewContext.ClientValidationEnabled = true; helper.ViewContext.UnobtrusiveJavaScriptEnabled = true; helper.ViewContext.FormContext = new FormContext(); helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); using (new CultureReplacer("en-US", "en-US")) { // Act MvcHtmlString html = helper.DropDownListFor(m => m.ElementAt(0).foo, selectList); // Assert Assert.Equal( "<select data-val=\"true\" data-val-required=\"The foo field is required.\" id=\"MyPrefix_foo\" name=\"MyPrefix.foo\"><option value=\"A\">Alpha</option>" + Environment.NewLine + "<option value=\"B\">Bravo</option>" + Environment.NewLine + "<option selected=\"selected\" value=\"C\">Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); } }
private void Construct(CharityRequirement charity) { if (charity == null) CharityRequirement = new CharityRequirement(); else CharityRequirement = charity; var lookupRepository = new LookupRepository(); var infrastructureTechnologies = lookupRepository.GetAllTechnologies(); InfrastructureTechnologies = new SelectList(infrastructureTechnologies, "TechnologyID", "Description"); SupportSkills = new SelectList(infrastructureTechnologies, "TechnologyID", "Description"); }
public void DropDownListForWithObjectDictionaryAndEmptyOptionLabel() { // Arrange HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooModel>()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.DropDownListFor(m => m.foo, selectList, String.Empty /* optionLabel */, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( "<select baz=\"BazObjValue\" id=\"foo\" name=\"foo\"><option value=\"\"></option>" + Environment.NewLine + "<option>Alpha</option>" + Environment.NewLine + "<option>Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// GET: CompanyJobPocoes/Create public IActionResult Create() { ViewData["Company"] = new SelectList(_context.CompanyProfiles, "Id", "Id"); return(View()); }
// GET: Bookings/Create public IActionResult Create() { ViewData["CustomerId"] = new SelectList(_context.Set <Customer>(), "id", "Address"); ViewData["RoomId"] = new SelectList(_context.Set <Room>(), "id", "Category"); return(View()); }
public void DropDownListForWithNullExpressionThrows() { // Arrange HtmlHelper<object> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<object>()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleAnonymousObjects(), "Letter", "FullWord", "C"); // Act & Assert Assert.ThrowsArgumentNull( () => helper.DropDownListFor<object, object>(null /* expression */, selectList), "expression" ); }
// GET: Interests/Create public IActionResult Create() { ViewData["FkCompaniesId"] = new SelectList(_context.Companies, "CompaniesId", "CompanyName"); return(PartialView()); }
public void DropDownListForUsesLambdaDefaultValue() { // Arrange HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(_dropDownListViewData); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.DropDownListFor(m => m.foo, selectList); // Assert Assert.Equal( "<select id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// GET: Correspondenciaexternas/Create public IActionResult Create() { ViewData["Idcontactodestinatario"] = new SelectList(_context.Contactos, "Idcontacto", "Nombre"); ViewData["Idcontactoremitente"] = new SelectList(_context.Contactos, "Idcontacto", "Nombre"); return(View()); }
public void DropDownListWithErrors() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings(), new[] { "Charlie" }); ViewDataDictionary viewData = GetViewDataWithErrors(); HtmlHelper helper = MvcHelper.GetHtmlHelper(viewData); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, null /* optionLabel */, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( "<select baz=\"BazObjValue\" class=\"input-validation-error\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public IActionResult OnGet() { ViewData["DepartmentId"] = new SelectList(_context.Department, "Id", "Name"); return Page(); }
public void DropDownListWithErrorsAndCustomClass() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); ViewDataDictionary viewData = GetViewDataWithErrors(); HtmlHelper helper = MvcHelper.GetHtmlHelper(viewData); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, null /* optionLabel */, new { @class = "foo-class" }); // Assert Assert.Equal( "<select class=\"input-validation-error foo-class\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public void DropDownListUsesModelState() { // Arrange SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); ViewDataDictionary viewData = GetViewDataWithErrors(); viewData["foo"] = selectList; HtmlHelper helper = MvcHelper.GetHtmlHelper(viewData); // Act MvcHtmlString html = helper.DropDownList("foo"); // Assert Assert.Equal( "<select class=\"input-validation-error\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option selected=\"selected\">Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
public void DropDownListWithObjectDictionaryWithUnderscoresAndSelectListNoOptionLabel() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.DropDownList("foo", selectList, HtmlHelperTest.AttributesObjectUnderscoresDictionary); // Assert Assert.Equal( "<select foo-baz=\"BazObjValue\" id=\"foo\" name=\"foo\"><option>Alpha</option>" + Environment.NewLine + "<option>Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// Cria as listas de BU, CC e Linha public void setBUCCLINHA(int idWorkzone = 0) { var listaBU = new List <SelectListItem>(); var listaCC = new List <SelectListItem>(); var listaLinha = new List <SelectListItem>(); var indexBU = 0; var indexCC = 0; var indexLinha = 0; try { var permissions = AuthorizationHelper.GetSystem(); var grupo = permissions.GruposDeSistema.Find(g => g.Nome == "Grupo_CentroCusto_Linha"); foreach (var bu in grupo.Funcionalidades.Filhos) { var itemBU = new SelectListItem { Selected = false, Text = bu.Nome, Value = bu.Nome }; listaBU.Insert(indexBU, itemBU); indexBU++; foreach (var f2 in bu.Filhos) { var itemCC = new SelectListItem { Selected = false, Text = f2.Nome, Value = bu.Nome }; listaCC.Insert(indexCC, itemCC); indexCC++; foreach (var f3 in f2.Filhos) { var itemLinha = new SelectListItem { Selected = false, Text = f3.Nome, Value = f3.Nome }; listaLinha.Insert(indexLinha, itemLinha); indexLinha++; } } } } catch { if (idWorkzone != 0) { var workzone = _workzone.GetWorkzoneById(idWorkzone); var itemBU = new SelectListItem { Selected = false, Text = workzone.idBU, Value = workzone.idBU }; listaBU.Insert(indexBU, itemBU); var itemCC = new SelectListItem { Selected = false, Text = workzone.idCC, Value = workzone.idCC }; listaCC.Insert(indexCC, itemCC); var itemLinha = new SelectListItem { Selected = false, Text = workzone.idLinha, Value = workzone.idLinha }; listaLinha.Insert(indexLinha, itemLinha); } else { var itemBU = new SelectListItem { Selected = false, Text = "", Value = "" }; listaBU.Insert(indexBU, itemBU); var itemCC = new SelectListItem { Selected = false, Text = "", Value = "" }; listaCC.Insert(indexCC, itemCC); var itemLinha = new SelectListItem { Selected = false, Text = "", Value = "" }; listaLinha.Insert(indexLinha, itemLinha); } } SelectList BU = new SelectList(listaBU, "Value", "Text"); SelectList CC = new SelectList(listaCC, "Value", "Text"); SelectList Linha = new SelectList(listaLinha, "Value", "Text"); ViewData["BU"] = BU; ViewData["CC"] = CC; ViewData["LINHA"] = Linha; }
// GET: Books/Create public IActionResult Create() { ViewData["GenId"] = new SelectList(_context.Genres, "GenId", "Description"); ViewData["Id"] = new SelectList(_context.Publicist, "Id", "Address"); return(View()); }
// GET: Albums/Create public IActionResult Create() { ViewData["ArtistID"] = new SelectList(_context.Artists, "ArtistID", "Name"); ViewData["GenreID"] = new SelectList(_context.Genres, "GenreID", "Name"); return(View()); }
public void DropDownListWithPrefixAndEmptyName() { // Arrange HtmlHelper helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; // Act MvcHtmlString html = helper.DropDownList("", selectList, HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( "<select baz=\"BazObjValue\" id=\"MyPrefix\" name=\"MyPrefix\"><option>Alpha</option>" + Environment.NewLine + "<option>Bravo</option>" + Environment.NewLine + "<option>Charlie</option>" + Environment.NewLine + "</select>", html.ToHtmlString()); }
// GET: Anggota/Create public IActionResult Create() { ViewData["Kd_wilayah"] = new SelectList(_context.Wilayah, "Kd_wilayah", "Nama_Wilayah"); ViewData["IdPengurus"] = new SelectList(_context.Pengurus, "IdPengurus", "Username"); return(View()); }
public void DataGroupFieldSetByCtor() { // Arrange IEnumerable items = new object[0]; object selectedValue = new object(); // Act SelectList selectList = new SelectList(items, "SomeValueField", "SomeTextField", "SomeGroupField", selectedValue); IEnumerable selectedValues = selectList.SelectedValues; // Assert Assert.Same(items, selectList.Items); Assert.Equal("SomeValueField", selectList.DataValueField); Assert.Equal("SomeTextField", selectList.DataTextField); Assert.Equal("SomeGroupField", selectList.DataGroupField); Assert.Same(selectedValue, selectList.SelectedValue); Assert.Single(selectedValues, selectedValue); Assert.Null(selectList.DisabledValues); Assert.Null(selectList.DisabledGroups); }
// GET: Departments/Create public IActionResult Create() { ViewData["InstructorID"] = new SelectList(_context.Instructors, "ID", "FullName"); return View(); }
public async Task<IActionResult> Edit(int? id, byte[] rowVersion) { if (id == null) { return NotFound(); } var departmentToUpdate = await _context.Departments.Include(i => i.Administrator).SingleOrDefaultAsync(m => m.DepartmentID == id); if (departmentToUpdate == null) { Department deletedDepartment = new Department(); await TryUpdateModelAsync(deletedDepartment); ModelState.AddModelError(string.Empty, "Unable to save changes. The department was deleted by another user."); ViewData["InstructorID"] = new SelectList(_context.Instructors, "ID", "FullName", deletedDepartment.InstructorID); return View(deletedDepartment); } _context.Entry(departmentToUpdate).Property("RowVersion").OriginalValue = rowVersion; if (await TryUpdateModelAsync<Department>( departmentToUpdate, "", s => s.Name, s => s.StartDate, s => s.Budget, s => s.InstructorID)) { try { await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } catch (DbUpdateConcurrencyException ex) { var exceptionEntry = ex.Entries.Single(); var clientValues = (Department)exceptionEntry.Entity; var databaseEntry = exceptionEntry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save changes. The department was deleted by another user."); } else { var databaseValues = (Department)databaseEntry.ToObject(); if (databaseValues.Name != clientValues.Name) { ModelState.AddModelError("Name", $"Current value: {databaseValues.Name}"); } if (databaseValues.Budget != clientValues.Budget) { ModelState.AddModelError("Budget", $"Current value: {databaseValues.Budget:c}"); } if (databaseValues.StartDate != clientValues.StartDate) { ModelState.AddModelError("StartDate", $"Current value: {databaseValues.StartDate:d}"); } if (databaseValues.InstructorID != clientValues.InstructorID) { Instructor databaseInstructor = await _context.Instructors.SingleOrDefaultAsync(i => i.ID == databaseValues.InstructorID); ModelState.AddModelError("InstructorID", $"Current value: {databaseInstructor?.FullName}"); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); departmentToUpdate.RowVersion = (byte[])databaseValues.RowVersion; ModelState.Remove("RowVersion"); } } } ViewData["InstructorID"] = new SelectList(_context.Instructors, "ID", "FullName", departmentToUpdate.InstructorID); return View(departmentToUpdate); }
public void DropDownListForWithObjectDictionaryAndTitle() { // Arrange HtmlHelper<FooModel> helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<FooModel>()); SelectList selectList = new SelectList(MultiSelectListTest.GetSampleStrings()); // Act MvcHtmlString html = helper.DropDownListFor(m => m.foo, selectList, "[Select Something]", HtmlHelperTest.AttributesObjectDictionary); // Assert Assert.Equal( @"<select baz=""BazObjValue"" id=""foo"" name=""foo""><option value="""">[Select Something]</option> <option>Alpha</option> <option>Bravo</option> <option>Charlie</option> </select>", html.ToHtmlString()); }
void ControlTreeDataLoader.LoadData() { CssClass = CssClass.ConcatenateWithSpace( CssElementCreator.CssClass ); if( minuteInterval < 30 ) { textBox = new EwfTextBox( value.HasValue ? value.Value.ToTimeOfDayHourAndMinuteString() : "", disableBrowserAutoComplete: true, postBack: postBack, autoPostBack: autoPostBack ); Controls.Add( new ControlLine( textBox, getIconButton() ) ); } else { var minuteValues = new List<int>(); for( var i = 0; i < 60; i += minuteInterval ) minuteValues.Add( i ); selectList = SelectList.CreateDropDown( from hour in Enumerable.Range( 0, 24 ) from minute in minuteValues let timeSpan = new TimeSpan( hour, minute, 0 ) select SelectListItem.Create<TimeSpan?>( timeSpan, timeSpan.ToTimeOfDayHourAndMinuteString() ), value, width: Unit.Percentage( 100 ), placeholderIsValid: true, placeholderText: "", postBack: postBack, autoPostBack: autoPostBack ); Controls.Add( selectList ); } if( ToolTip != null || ToolTipControl != null ) new ToolTip( ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl( ToolTip ), this ); }
// GET: RUTA/Create public IActionResult Create() { ViewData["ClientId"] = new SelectList(_context.Client, "Id", "Id"); ViewData["VehicleId"] = new SelectList(_context.Set <Vehicle>(), "Id", "Id"); return(View()); }