本文整理汇总了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));
}
示例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; }
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
}
示例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);
}
示例13: EditFunction
public ActionResult EditFunction(SelectListItem functionWithComment)
{
if (functionWithComment == null) return View();
PerformerStatFilteredViewModel.AddFunction(functionWithComment.Text, functionWithComment.Value);
// перенаправить на страницу отчета
return RedirectToAction("TraderRate");
}
示例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() );
}
示例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();
}