本文整理汇总了C#中System.Web.Mvc.SelectList.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# SelectList.ToList方法的具体用法?C# SelectList.ToList怎么用?C# SelectList.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.SelectList
的用法示例。
在下文中一共展示了SelectList.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToSelectList
public static SelectList ToSelectList(this IEnumerable list, string selectedItem, string textFieldName, string valueFieldName, string captionName = "", string captionValue = "0")
{
SelectList selectList = new SelectList(list, valueFieldName, textFieldName, selectedItem);
if (!string.IsNullOrEmpty(captionName))
{
var lst = selectList.ToList();
lst.Insert(0, new SelectListItem
{
Text = captionName,
Value = captionValue
});
selectList = new SelectList(lst.ToList(), "Value", "Text");
}
if (!string.IsNullOrEmpty(selectedItem) && selectList.SelectedValue == null)
{
SelectListItem item = selectList.ToList().FirstOrDefault(x => x.Value.ToLower() == selectedItem.ToLower());
if (item != null && item.Value.ToLower() == selectedItem.ToLower())
{
item.Selected = true;
}
}
return selectList;
}
示例2: Create
public ActionResult Create()
{
User user = GetCurrentUser();
IEnumerable<User> _Users = GetMyUser();
SelectList Users = new SelectList(_Users, "USERID", "USERNAME",user.USERID);
var usersList = Users.ToList();
ViewBag.UserId = usersList;
return View(new Order { CustomerStatus= "新签", Idea= "自选", Product= "仅百度", ShopStatus= "未跟进", OrderStatus= "开通" });
}
示例3: DeleteUser
public ActionResult DeleteUser(string sms)
{
TempData["Msg"] = sms;
var Roles = from d in objBs.tuserBs.GetAll()
select d;
var ddlUsers = new SelectList(Roles, "UserEmail", "UserEmail");
ViewBag.ddlUsers = ddlUsers.ToList();
return View();
}
示例4: datosEquipos
public ActionResult datosEquipos(int equipo1)
{
var tel = (from e in db.Usuarios
where e.equipo_id == equipo1
select e).Select(model => model.telefono);
SelectList datos = new SelectList(tel.ToList(), "telefono");
return Json(datos.ToList());
}
示例5: GenericSelectList
public static SelectList GenericSelectList(AssetManagerContext db, Type entityType
, string property, object selectedvalue)
{
var set = db.Set(entityType);
var query = set.OrderBy(property)
.Select("new(" + property + ")")
.Distinct()
;
SelectList selectlist = new SelectList(query, property, property, selectedvalue);
string selected = selectedvalue.ToStringOrEmpty();
if (!string.IsNullOrWhiteSpace(selected) && !selectlist.Contains(selectedvalue))
{
List<SelectListItem> list = selectlist.ToList();
list.Add(new SelectListItem { Text = selected, Value = selected });
list.Sort((x, y) => x.Text.CompareTo(y.Text));
selectlist = new SelectList(list, "Value", "Text", selectedvalue);
}
return selectlist;
}
示例6: Edit
public ActionResult Edit(int id)
{
ShopModel shopModel = new ShopModel();
Shop shopBaseInfo = shopModel.GetShop(id);
UserModel userModel = new UserModel();
UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
if(userInfo.UserGradeCategory.GradeLevel != 9 && shopBaseInfo.CreateBy != userInfo.Id)
return Redirect("/");
List<V_ShopDisheWithCategory> shopDisheWithCategory = shopModel.GetShopDishesWithCategory(id).OrderByDescending(r => r.DisheCategoryOrder).ToList();
var shopCategories = shopModel.GetShopCategories();
SelectList shopCategoryList = new SelectList(shopCategories, "Id", "Value");
List<SelectListItem> shopCategorySelectList = shopCategoryList.ToList();
for(int i = 0; i < shopCategorySelectList.Count; i++)
if(shopCategorySelectList[i].Value == shopBaseInfo.CategoryId.ToString())
{
shopCategorySelectList[i].Selected = true;
break;
}
ViewBag.ShopCategorySelectList = shopCategorySelectList;
BaseDataModel baseDataModel = new BaseDataModel();
var cityDistricts = baseDataModel.GetLocationsByParentId(214);
ViewBag.CityDistrictSelectList = (new SelectList(cityDistricts, "Id", "Value")).ToList();
List<ServiceArea> shopServiceAraes = shopModel.GetShopServiceAreas(id).ToList()
.Select(r => new ServiceArea() { Id = r.AreaId, ParentId = r.ParentId, Value = r.ServiceArea, AreaType = r.AreaType }).ToList();
ViewBag.ServiceAreaSelectList = shopServiceAraes;
ViewBag.ShopDisheCategoryList = shopDisheWithCategory.GroupBy(r => new { r.CategoryId, r.CategoryValue })
.Select(r => new SelectListItem() { Value = r.Key.CategoryId.ToString(), Text = r.Key.CategoryValue }).ToList();
ViewBag.ShopLogo = Url.Content(shopImagePath + shopBaseInfo.Logo);
ViewBag.OffsetTime = offsetTime;
return View(new ShopDetailEditorModel(shopBaseInfo, shopDisheWithCategory));
}
示例7: Create
public ActionResult Create(int i = 1)
{
ShopModel shopModel = new ShopModel();
var shopCategories = shopModel.GetShopCategories();
SelectList shopCategoryList = new SelectList(shopCategories, "Id", "Value");
List<SelectListItem> shopCategorySelectList = shopCategoryList.ToList();
ViewBag.ShopCategorySelectList = shopCategorySelectList;
BaseDataModel baseDataModel = new BaseDataModel();
var cityDistricts = baseDataModel.GetLocationsByParentId(214);
ViewBag.CityDistrictSelectList = (new SelectList(cityDistricts, "Id", "Value")).ToList();
ViewBag.ServiceAreaSelectList = new List<ServiceArea>();
ViewBag.ShopDisheCategoryList = new List<SelectListItem>();
ViewBag.ShopLogo = Url.Content("/Contents/ShopImages/shop_default_icon.png");
ViewBag.OffsetTime = offsetTime;
return View("Edit");
}
示例8: CategoryCreate
public ActionResult CategoryCreate(int? Id, int? mesaj)
{
if (Session["user_id"] == null)
return RedirectToAction("Default", "Home");
int user_id = Convert.ToInt32(Session["user_id"].ToString());
var u = db.dt_user.Where(a => a.state == 1 && a.ID == user_id).FirstOrDefault();
if (u == null)
return RedirectToAction("Default", "Home");
ViewBag.userName = u.name + " " + u.surname;
if (mesaj != null)
TempData["mesaj"] = mesaj.ToString();
int companyId;
if (Id == null)
companyId = 0;
else
companyId = (int)Id;
List<SelectListItem> list = TumSirket(companyId);
int companyid;
if (Id == null)
companyid = Convert.ToInt32(list.ToList().First().Value);
else
companyid = companyId;
List<SelectListItem> listCategory = new SelectList(db.dt_category.ToList().Where(a => a.state == 1 && a.company_id == companyid), "ID", "name").ToList<SelectListItem>();
SelectListItem it = new SelectListItem();
it.Text = "Üst Kategori";
it.Value = "0";
listCategory.Add(it);
ViewBag.company_id = list.ToList();
ViewBag.upCategoryID = listCategory.ToList();
return View();
}
示例9: TumSirket
/*----------Category data update,delete,select
---------Write 08.01.2013
---------M.Emin Yalçın-----*/
public List<SelectListItem> TumSirket(int? Id)
{
List<SelectListItem> list = new SelectList(db.dt_company.ToList().Where(a => a.active == 1), "ID", "companyname", Id).ToList<SelectListItem>();
return list.ToList();
}
示例10: SirketGoster
public void SirketGoster(int Id, int parentId)
{
List<SelectListItem> list = new SelectList(db.dt_company.ToList().Where(a => a.active == 1 && a.ID != Id && a.parentID != Id), "ID", "companyname", parentId).ToList<SelectListItem>();
SelectListItem it = new SelectListItem();
it.Text = "Merkezi Şirket";
it.Value = "0";
list.Add(it);
if (parentId == 0)
list.Reverse();
ViewBag.companyId = list.ToList();
}
示例11: Index
public ActionResult Index(string CorporationName,string DepartmentId, string Owner, string TelePhone, string MobilePhone, string StartTime, string EndTime, int? page)
{
IEnumerable<Department> _Departments = GetMyDepartmentList();
SelectList Departments = new SelectList(_Departments, "DEPARTMENTID", "DEPARTMENTNAME", DepartmentId);
var DepartmentList = Departments.ToList();
if (_Departments.Count() > 1)
{
DepartmentList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
}
ViewBag.Department = DepartmentList;
IEnumerable<User> _Users = GetMyUser(DepartmentId);
SelectList Users = new SelectList(_Users, "USERID", "USERNAME", Owner);
var usersList = Users.ToList();
if (_Users.Count() > 1)
{
usersList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
}
ViewBag.Owner = usersList;
ViewBag.CorporationNameParams = CorporationName;
ViewBag.DepartmentIdParams = DepartmentId;
ViewBag.UserIdParams = Owner;
ViewBag.TelePhoneParams = TelePhone;
ViewBag.MobilePhoneParams = MobilePhone;
ViewBag.StartTimeParams = StartTime;
ViewBag.EndTimeParams = EndTime;
var orders = from item in db.Order
select item;
if (!string.IsNullOrEmpty(CorporationName))
{
orders = orders.Where(x => x.Customer.CorporationName.Contains(CorporationName));
}
if (!string.IsNullOrEmpty(TelePhone))
{
orders = orders.Where(x => x.Customer.Tel.Contains(TelePhone));
}
if (!string.IsNullOrEmpty(MobilePhone))
{
orders = orders.Where(x => x.Customer.MobileTel.Contains(MobilePhone));
}
long depId = Convert.ToInt64(DepartmentId);
if (depId > 0)
{
orders = orders.Where(c => c.Customer.DepartmentID == depId);
}
if (Owner == null)
{
long id = GetCurrentUser().USERID;
orders = orders.Where(x => x.UserId == id);
}
if (Owner != null && Owner != "0")
{
long userId = Convert.ToInt64(Owner);
orders = orders.Where(x => x.UserId == userId);
}
if (!string.IsNullOrEmpty(StartTime) && !string.IsNullOrEmpty(EndTime))
{
DateTime st = DateTime.Parse(DateTime.Parse(StartTime).ToString("yyyy-MM-dd 00:00:00"));
DateTime et = DateTime.Parse(DateTime.Parse(EndTime).ToString("yyyy-MM-dd 23:59:59"));
orders = orders.Where(x => x.CreateDate.Value >= st && x.CreateDate <= et);
}
orders = orders.OrderByDescending(c => c.CreateDate);
int pageNumber = (page ?? 1);
return View(orders.ToPagedList(pageNumber, pageSize));
//return View(new Person { Name = "Foo", Gender = "F", MaritalStatus = "M", Country = new string[] { "CN", "US","UK" } });
}
示例12: GetCategory
public List<SelectListItem> GetCategory(int? categoryId, int companyId)
{
List<SelectListItem> list = new SelectList(db.dt_category.ToList().Where(a => a.state == 1 && a.company_id == companyId && a.upCategoryID != categoryId && a.ID != categoryId), "ID", "name", categoryId).ToList<SelectListItem>();
return list.ToList();
}
示例13: Statics
public ActionResult Statics(StaticsSearchParams param)
{
ViewBag.IsRole = IsRole;
User Current = GetCurrentUser();
var statusSelectList = GetStatusList(param.Status).ToList();
statusSelectList.Insert(0, new SelectListItem() { Text = "全部", Value = "" });
ViewBag.Status = statusSelectList;
//IEnumerable<User> _Users = GetMyUser();
if (string.IsNullOrEmpty(param.Owner))
{
param.Owner = Current.USERID.ToString();
}
IEnumerable<Department> _Departments = GetMyDepartmentList();
SelectList Departments = new SelectList(_Departments, "DEPARTMENTID", "DEPARTMENTNAME", param.DepartmentId);
var DepartmentList = Departments.ToList();
if (_Departments.Count() > 1)
{
DepartmentList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
}
ViewBag.Department = DepartmentList;
IEnumerable<User> _Users = GetMyUser(param.DepartmentId);
SelectList Users = new SelectList(_Users, "USERID", "USERNAME", param.Owner);
var usersList = Users.ToList();
if (_Users.Count() > 1)
{
usersList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
}
ViewBag.Owner = usersList;
//SelectList Users = new SelectList(_Users, "USERID", "USERNAME", param.Owner);
//var usersList = Users.ToList();
//if (_Users.Count() > 1)
//{
// usersList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
//}
//ViewBag.Owner = usersList;
ViewBag.NextContractStartTimeParams = param.NextContractStartTime;
ViewBag.NextContractEndTimeParams = param.NextContractEndTime;
ViewBag.CreateDateStartTimeParams = param.CreateDateStartTime;
ViewBag.CreateDateEndTimeParams = param.CreateDateEndTime;
string sql = @"select U.USERNAME, [Status],COUNT(0) Total from [dbo].[Customer] as c
inner join [dbo].[User] as u
on c.[Owner]=u.USERID
where [PoolStatus]=1 {0}
group by U.USERNAME, [Status]
order by u.username,[Status],total desc";
StringBuilder sb = new StringBuilder();
if (!string.IsNullOrEmpty(param.Status) && param.Status != "0")
{
sb.AppendFormat(" and c.[Status]='{0}' ", param.Status);
}
if (!string.IsNullOrEmpty(param.Owner) && param.Owner != "0")
{
sb.AppendFormat(" and c.[Owner]={0} ", param.Owner);
}
if (!string.IsNullOrEmpty(param.NextContractStartTime) && !string.IsNullOrEmpty(param.NextContractEndTime))
{
sb.AppendFormat(" and c.[NextContactTime] >='{0} 00:00:00' and c.[NextContactTime]<='{1} 23:59:59' ", Convert.ToDateTime(param.NextContractStartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(param.NextContractEndTime).ToString("yyyy-MM-dd"));
}
if (!string.IsNullOrEmpty(param.CreateDateStartTime) && !string.IsNullOrEmpty(param.CreateDateEndTime))
{
sb.AppendFormat(" and c.[CreateDate] >='{0} 00:00:00' and c.[CreateDate]<='{1} 23:59:59' ", Convert.ToDateTime(param.CreateDateStartTime).ToString("yyyy-MM-dd"), Convert.ToDateTime(param.CreateDateEndTime).ToString("yyyy-MM-dd"));
}
if (Current.Role.ROLENAME == "销售经理")
{
//仅能看部门内数据
sb.AppendFormat(" and c.[DepartmentID]={0} ", Current.DEPARTMENTID);
}
else if (Current.Role.ROLENAME == "高级销售经理-群总" || Current.Role.ROLENAME == "销售总监" || Current.Role.ROLENAME == "高级管理员")
{
long depId = Convert.ToInt64(param.DepartmentId);
if (depId > 0)
{
sb.AppendFormat(" and c.[DepartmentID]={0} ", param.DepartmentId);
}
else
{
long currentUid = Current.USERID;
var authDeps = from auth in db.Authority
where auth.UserId == currentUid
select auth.DepartmentId;
if (authDeps.Count() > 0)
{
StringBuilder sbDepIds = new StringBuilder();
foreach (var item in authDeps)
{
if(sbDepIds.Length==0)
{
sbDepIds.Append(item);
}
else
{
sbDepIds.Append("," + item);
}
//.........这里部分代码省略.........
示例14: Register
public ActionResult Register(string sms)
{
TempData["Msg"] = sms;
var Roles = from d in objBs.roleBs.GetAll()
select d;
var ddlRoles = new SelectList(Roles, "RoleId", "RoleDesc");
ViewBag.ddlRoles = ddlRoles.ToList();
return View();
}
示例15: Week
public ActionResult Week(string CorporationName, string fromType, string Owner, string status, string NextContractStartTime, string NextContractEndTime, int? page)
{
InitPageSize();
var sourceFromList = GetSourceFrom(fromType).ToList();
var statusSelectList = GetStatusList(status).ToList();
sourceFromList.Insert(0, new SelectListItem() { Text = "全部", Value = "" });
statusSelectList.Insert(0, new SelectListItem() { Text = "全部", Value = "" });
ViewBag.SourceFrom = sourceFromList;
ViewBag.Status = statusSelectList;
IEnumerable<User> _Users = GetMyUser();
SelectList Users = new SelectList(_Users, "USERID", "USERNAME", Owner);
var usersList = Users.ToList();
if (_Users.Count() > 1)
{
usersList.Insert(0, new SelectListItem() { Text = "全部", Value = "0" });
}
ViewBag.Owner = usersList;
ViewBag.CorporationNameParams = CorporationName;
ViewBag.UserIdParams = Owner;
ViewBag.fromTypeParams = fromType;
ViewBag.StatusParams = status;
ViewBag.NextContractStartTimeParams = NextContractStartTime;
ViewBag.NextContractEndTimeParams = NextContractEndTime;
DateTime beginDate;
DateTime endDate;
DateTime nowDate = DateTime.Now;
beginDate = nowDate.Date.AddDays(1 - Convert.ToInt32(nowDate.DayOfWeek.ToString("d")));
endDate = beginDate.Date.AddDays(7).AddSeconds(-1);
var customers = from item in db.Customer
where item.PoolStatus.Value == privateTag && item.CreateDate.Value >= beginDate && item.CreateDate.Value <= endDate
select item;
if (!string.IsNullOrEmpty(CorporationName))
{
customers = customers.Where(x => x.CorporationName.Contains(CorporationName));
}
if (Owner == null)
{
long id = GetCurrentUser().USERID;
customers = customers.Where(x => x.Owner == id);
}
if (Owner != null && Owner != "0")
{
long userId = Convert.ToInt64(Owner);
customers = customers.Where(x => x.Owner == userId);
}
if (!string.IsNullOrEmpty(fromType))
{
customers = customers.Where(x => x.SourseFrom == fromType);
}
if (!string.IsNullOrEmpty(status))
{
customers = customers.Where(x => x.Status == status);
}
if (!string.IsNullOrEmpty(NextContractStartTime) && !string.IsNullOrEmpty(NextContractEndTime))
{
DateTime st = DateTime.Parse(DateTime.Parse(NextContractStartTime).ToString("yyyy-MM-dd 00:00:00"));
DateTime et = DateTime.Parse(DateTime.Parse(NextContractEndTime).ToString("yyyy-MM-dd 23:59:59"));
customers = customers.Where(x => x.NextContactTime.Value >= st && x.NextContactTime <= et);
}
//过滤角色数据
customers = Filter(customers);
customers = customers.OrderByDescending(c => c.CreateDate);
int pageNumber = (page ?? 1);
return View(customers.ToPagedList(pageNumber, pageSize));
}