本文整理汇总了C#中System.Web.Mvc.SelectList.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# SelectList.Insert方法的具体用法?C# SelectList.Insert怎么用?C# SelectList.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.SelectList
的用法示例。
在下文中一共展示了SelectList.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
// GET: Schedules/Create
public ActionResult Create(int? departmentId, int? groupId)
{
Department department = db.Departments.Find(departmentId);
DepartmentGroup group = db.DepartmentGroups.Find(groupId);
if(department == null && group == null)
{
return HttpNotFound();
}
if (User.Identity.IsAuthenticated)
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
var currentUser = userManager.FindById(User.Identity.GetUserId());
if ((department != null && department.Bosses.Contains(currentUser)) || (group != null && group.Department.Bosses.Contains(currentUser)))
{
//ViewBag.DepartmentId = new SelectList(db.Departments.ToList().Where(q=>q.Bosses.Contains(currentUser)).ToList(), "Id","Name",departmentId);
//ViewBag.GroupId = new SelectList(db.DepartmentGroups.ToList().Where(q=>q.Department.Bosses.Contains(currentUser)).ToList(), "Id","Name",groupId);
ViewBag.DepartmentId = new SelectList(db.Departments.ToList().Where(q => q.Bosses.Contains(currentUser)).ToList(), "Id", "Name", departmentId);
var groups = new SelectList(db.DepartmentGroups.ToList().Where(q => q.Department.Bosses.Contains(currentUser)).ToList(), "Id", "Name", groupId).ToList();
groups.Insert(0,new SelectListItem() { Value = "", Text = "All" });
ViewBag.GroupId = groups;
return View();
}
else
{
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
}
}
else
{
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
}
}
示例2: Create
public ActionResult Create(ProductModel model)
{
var _brands = unitOfWork.BrandRepository.FindAllBy(c => c.IsActive == true && c.IsDelete == false).Select(x => new { x.ID, x.Name });
ViewBag.Brands = new SelectList(_brands, "ID", "Name");
var _locations = unitOfWork.LocationRepository.FindAllBy(c => c.IsActive == true && c.IsDelete == false).Select(x => new { x.LocationCode, x.LocationName });
List<SelectListItem> items = new SelectList(_locations, "LocationCode", "LocationName").ToList();
items.Insert(0, (new SelectListItem { Text = "All", Value = "0" }));
ViewBag.Locations = items;
var _Categorys = unitOfWork.CategoryRepository.FindAllBy(c => c.IsActive == true && c.IsDelete == false).Select(x => new { x.ID, x.Name });
ViewBag.Categorys = new SelectList(_Categorys, "ID", "Name");
ViewBag.Images = unitOfWork.ProductsImagesRepository.FindAllBy(c => c.ProductCode == model.ProductCode);
ViewBag.Videos = unitOfWork.ProductsVideosRepository.FindAllBy(c => c.ProductCode == model.ProductCode);
try
{
if (ModelState.IsValid)
{
var _updatedata = unitOfWork.ProductRepository.FindAllBy(c => c.ProductCode == model.ProductCode).FirstOrDefault();
if (_updatedata ==null)
{
unitOfWork.ProductRepository.Insert(model);
unitOfWork.Save();
}
else
{
_updatedata.IsActive = model.IsActive;
_updatedata.IsDelete = false;
_updatedata.ListPrice = model.ListPrice;
_updatedata.LocationCode = model.LocationCode;
_updatedata.ProductCode = model.ProductCode;
_updatedata.ProductName = model.ProductName;
_updatedata.ShortDescription = model.ShortDescription;
_updatedata.CategoryID = model.CategoryID;
_updatedata.StandardCost = model.StandardCost;
_updatedata.LastUpdate = DateTime.Now;
unitOfWork.ProductRepository.Update(_updatedata);
unitOfWork.Save();
}
return RedirectToAction("Index");
}
return View(model);
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
Trace.TraceInformation("Property: {0} Error: {1}",
validationError.PropertyName,
validationError.ErrorMessage);
}
}
return View(model);
}
}
示例3: SelectList
public static SelectList SelectList(IEnumerable items, string valueField, string textField, string nullText, string selectedValue)
{
var list = new SelectList(items, valueField, textField, selectedValue).ToList();
var selected = list.Where(x => x.Value == selectedValue).FirstOrDefault();
if (selected != null) selected.Selected = true;
if (nullText != null) list.Insert(0, new SelectListItem { Text = nullText, Value = 0.ToString() });
return new SelectList(list, "Value", "Text", selectedValue);
}
示例4: InventoryDetail
/// <summary>
/// Displays the list of inventory
/// </summary>
/// <returns></returns>
public ActionResult InventoryDetail()
{
StringBuilder objStringBuilderError = new StringBuilder();
try
{
if (Session["UserName"] != null)
{
InventorySearchModel inventorySearchModel = new InventorySearchModel();
IEnumerable<InventoryModel> lstInventoryDetails;
List<DeviceModel> devices;
using (JetstreamClient objMainServiceClient = new JetstreamClient())
{
lstInventoryDetails = objMainServiceClient.GetInventoryList(inventorySearchModel.LogicalDeviceId, inventorySearchModel.SearchString);
devices = objMainServiceClient.GetDeviceList();
}
List<SelectListItem> deviceList = new SelectList(devices.OrderBy(x => x.LogicalDeviceId), "LogicalDeviceId", "LogicalDeviceId").ToList();
deviceList.Insert(0, new SelectListItem { Text = JetstreamResource.All, Value = string.Empty });
ViewBag.DeviceList = deviceList;
SortingPagingInfo info = new SortingPagingInfo
{
SortField = Enums.InventorySortField.Material.ToString(),
SortDirection = Constants.Ascending,
};
lstInventoryDetails = lstInventoryDetails.OrderBy(x => x.Material).Take(Constants.PagingPageSize);
ViewBag.SortingPagingInfo = info;
if (lstInventoryDetails.Any())
inventorySearchModel.InventoryModels = lstInventoryDetails.ToList();
return View("InventoryDetail", inventorySearchModel);
}
else
{
return RedirectToAction("UserLogin", "Login");
}
}
catch (FaultException<ServiceData> fex)
{
objStringBuilderError.AppendLine("In method : InventoryDetail() :: InventoryController");
objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", fex.Detail.ErrorMessage, Environment.NewLine);
objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, fex.Detail.ErrorDetails);
SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
return View("Error");
}
catch (Exception ex)
{
objStringBuilderError.AppendLine("In method : InventoryDetail() :: InventoryController");
objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());
SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
return View("Error");
}
}
示例5: GetSearchType
private async Task GetSearchType(int roomallocationid)
{
List<SelectListItem> items = new SelectList(await _RoomAllocationRepository.GetAll(), "Id", "RoomNumber", roomallocationid).ToList();
items.Insert(0, (new SelectListItem { Text = "Select Room #", Value = "0" }));
ViewBag.SearchRoomAllocationId = items;
}
示例6: BindDevices
/// <summary>
/// Method to bind the devices to device dropdown
/// </summary>
private void BindDevices()
{
StringBuilder objStringBuilderError = new StringBuilder();
try
{
List<DeviceModel> devices;
using (JetstreamClient objMainServiceClient = new JetstreamClient())
{
devices = objMainServiceClient.GetDeviceList();
}
List<SelectListItem> deviceList = new SelectList(devices.OrderBy(x => x.LogicalDeviceId), "DeviceId", "LogicalDeviceId").ToList();
deviceList.Insert(0, new SelectListItem { Text = JetstreamResource.Device, Value = JetstreamResource.Zero });
ViewBag.DeviceList = deviceList;
}
catch (Exception ex)
{
objStringBuilderError.AppendLine("In method : BindDevices() :: TemperatureController");
objStringBuilderError.AppendFormat("ErrorMessage::{0} {1}", ex.Message, Environment.NewLine);
objStringBuilderError.AppendFormat("ErrorDetails::{0} {1}", Environment.NewLine, ex.ToString());
SaveLogger.SaveLoggerError(objStringBuilderError.ToString());
}
}
示例7: FillStatus
public async Task<List<RoomReservation_StatusViewModel>> FillStatus(RoomReservation_Status db_status=null, long reservation_id=0 )
{
var list = new List<RoomReservation_StatusViewModel>();
IEnumerable<ReservationStatusType> statuslist;
bool isShowdb_status = false;
if (db_status!=null)
{
if (! string.IsNullOrEmpty (db_status.ReservationStatusType.Next_Status))
{
string[] next_status = db_status.ReservationStatusType.Next_Status.Split(',');
statuslist = await _ReservationStatusTypeRepository.GetAllEnabledbyIds(next_status);
statuslist = statuslist.OrderByDescending(s => s.Id);
}
else
{
isShowdb_status = true;
statuslist = new List<ReservationStatusType> { db_status.ReservationStatusType };
}
}
else
{
statuslist = await _ReservationStatusTypeRepository.GetAllEnabled();
statuslist= statuslist.Where(s => s.IsDefault.Value).OrderByDescending(s => s.Id);
}
foreach (var status in statuslist)
{
RoomReservation_Status roomreservation_status;
if (isShowdb_status)
roomreservation_status =db_status;
else
roomreservation_status = new RoomReservation_Status();
RoomReservation_StatusViewModel roomreservation_statusviewmodel=new RoomReservation_StatusViewModel();
roomreservation_statusviewmodel.RoomReservation_Status = roomreservation_status;
roomreservation_statusviewmodel.RoomReservation_Status.ReservationStatusTypeId = status.Id;
if (status.Name == RoomReservationSystem.Model.Enums.eReservationStatusType.Cancelled.ToString())
{ // Things to do: create listtype webapi, and repository, listtype and reasons interface does not exists.
// var listType = await _ListTypesRepository.GetByName(RoomReservationSystem.Model.Enums.ListType.RoomReservation_CancelationReasons.ToString());
var cancellation_reasons = await _Reason_TypesRepository.GetbyListTypeId(((int)RoomReservationSystem.Model.Enums.ListType.RoomReservation_CancelationReasons).ToString());
var cancellation_reasons_selectlist = new SelectList(cancellation_reasons, "Id", "Name", roomreservation_status.Reason_TypeId).ToList();
cancellation_reasons_selectlist.Insert(0, new SelectListItem() { Text = "Select Reason", Value = "0" });
ViewBag.Reason_TypeId = cancellation_reasons_selectlist;
}
roomreservation_statusviewmodel.ReservationStatusType = status;
list.Add(roomreservation_statusviewmodel);
}
if (statuslist.Count()>0)
statuslist.First().IsDefault = true;
return list;
}
示例8: GetTypes
private async Task GetTypes(RoomReservationViewModel model=null)
{
ViewBag.Sponsor_ClubId = new SelectList(await _ClubRepository.GetAllEnabled(), "Id", "Name");
ViewBag.Reservation_SourceId = new SelectList(await _Reservation_SourceRepository.GetAllEnabled(), "Id", "Name");
ViewBag.CountryId = new SelectList(await _CountryRepository.GetAllEnabled(), "Id", "Name");
var default_language=await _LanguageRepository.GetByName(RoomReservationSystem.Model.Enums.Language.English.ToString());
var lang = await _LanguageRepository.GetAllEnabled();
ViewBag.LanguageID = new SelectList(lang.OrderBy(a=>a.Name), "Id", "Name", default_language.Id);
var titles=await _TitleRepository.GetAll();
var titles_selectlist = new SelectList(titles.OrderBy(a=>a.Name), "Id", "Name").ToList();
titles_selectlist.Insert(0, new SelectListItem() { Text = "Select Title", Value = "0", Selected =true});
ViewBag.TitleID = titles_selectlist;
var all_doctype = await _Document_TypeRepository.GetAllEnabled();
var doc_types = new SelectList(all_doctype, "Id", "Name", 0).ToList();
doc_types.Insert(0, new SelectListItem() { Text = "Select Type", Value = "0", Selected =true});
ViewBag.Document_TypeId = doc_types;
if (model == null)
{
var roomtypes = new SelectList(await _RoomTypeRepository.GetAllEnabled(), "Id", "Name").ToList();
roomtypes.Insert(0, new SelectListItem() { Text = "Room type", Value = "0" });
ViewData["RoomReservation_RoomDetails.RoomTypeId"] = roomtypes;
var wings = new SelectList(await _WingRepository.GetAllEnabled(), "Id", "Name").ToList();
wings.Insert(0, new SelectListItem() { Text = "Wing", Value = "0" });
ViewData["Wing.WingId"] = wings;
List<SelectListItem> room_allocation = new List<SelectListItem>();
room_allocation.Insert(0, new SelectListItem() { Text = "Room #", Value = "0" });
ViewData["RoomReservation_RoomDetails.RoomAllocationId_0"] = room_allocation;
}
else
{
var index = 0;
var roomtypeslist = _RoomTypeRepository.GetAllEnabled();
var wingslist = _WingRepository.GetAllEnabled();
foreach (var roomdetailviewmodel in model.RoomReservation_RoomDetailsViewDetailList)
{
var postfix = "_" + index;
var roomtypes = new SelectList(await roomtypeslist, "Id", "Name", roomdetailviewmodel.RoomReservation_RoomDetails.RoomTypeId).ToList();
roomtypes.Insert(0, new SelectListItem() { Text = "Room type", Value = "0" });
ViewData["RoomReservation_RoomDetails.RoomTypeId" + postfix] = roomtypes;
var wings = new SelectList(await wingslist, "Id", "Name", roomdetailviewmodel.Wing.Id).ToList();
wings.Insert(0, new SelectListItem() { Text = "Wing", Value = "0" });
ViewData["Wing.WingId" + postfix] = wings;
List<SelectListItem> room_allocation = new List<SelectListItem>();
if (roomdetailviewmodel.RoomReservation_RoomDetails.RoomTypeId.HasValue)
room_allocation = new SelectList(await _RoomAllocationRepository.GetByRoomTypeId(roomdetailviewmodel.RoomReservation_RoomDetails.RoomTypeId.Value), "Id", "Name", roomdetailviewmodel.RoomReservation_RoomDetails.RoomAllocationId).ToList();
room_allocation.Insert(0, new SelectListItem() { Text = "Room #", Value = "0" });
ViewData["RoomReservation_RoomDetails.RoomAllocationId" + postfix ] = room_allocation;
index++;
}
}
var reasons = new SelectList(await _Reason_TypeRepository.GetAllEnabled(), "Id", "Name" ).ToList();
ViewBag.Reason_TypeId = reasons;
var pkr=await _CurrencyRepository.GetByName(RoomReservationSystem.Model.Enums.Currency.PKR.ToString());
var currencies = new SelectList(await _CurrencyRepository.GetCurrencyForDropDoown(), "Id", "Label", pkr.Id + "|" + Math.Round (pkr.Rate.Value , 4) + "|" + pkr.Code).ToList();
currencies.Insert(0, new SelectListItem() { Text = "Select Currency", Value = "0" });
ViewBag.CurrencyId = currencies;
var paymentmodes_cash = await _PaymentModeRepository.GetByName(RoomReservationSystem.Model.Enums.PaymentMode.Cash.ToString () );
var paymentModes = new SelectList(await _PaymentModeRepository.GetAllEnabled(), "Id", "Name", paymentmodes_cash.Id ).ToList();
// paymentModes.Insert(0, new SelectListItem() { Text = "Select Payment mode", Value = "0" });
ViewBag.PaymentModeId = paymentModes;
//For radiobutton lists in payment info
var billtime= await _BillTimeRepository.GetAllEnabled();
ViewBag.BillTime_RadioButtonList = billtime.OrderByDescending(x => x.Id);
IEnumerable<PaymentBy> paymentby;
if (model == null)
paymentby = await _PaymentByRepository.PaymentBy_GetByIds((int)RoomReservationSystem.Model.Enums.BookingFor.Member, (int)RoomReservationSystem.Model.Enums.SponsorType.noType);
else
{
if (model.RoomReservation.BookingForId == (int)RoomReservationSystem.Model.Enums.BookingFor.Member)
//.........这里部分代码省略.........
示例9: GetSearchType
private async Task GetSearchType(int SearchRoomTypeId, int SearchWaitingListStatusId)
{
List<SelectListItem> items = new SelectList(await _RoomTypeRepository.GetAllEnabled(), "Id", "Name", SearchRoomTypeId).ToList();
items.Insert(0, (new SelectListItem { Text = "Any", Value = "0" }));
items.Insert(0, (new SelectListItem { Text = "Select room type", Value = "-1" }));
ViewBag.SearchRoomTypeId = items;
List<SelectListItem> status = new SelectList(await _WaitingListStatusRepository.GetAllEnabled(), "Id", "Name", SearchWaitingListStatusId).ToList();
status.Insert(0, (new SelectListItem { Text = "Select Status", Value = "0" }));
ViewBag.SearchWaitingListStatusId = status;
}
示例10: LlenarControles
private void LlenarControles(UsuarioModel model)
{
var proveedores = Uow.Proveedores.Listado().Where(p => p.CuentaId == UsuarioActual.CuentaId).ToList();
model.Proveedores = proveedores.Select(r => new SelectListItem()
{
Text = r.Nombre,
Value = r.ProveedorId.ToString()
}).ToList();
var listado = Uow.Usuarios.RolesListado().ToList();
listado.RemoveAt(3);
var roles = new SelectList(listado, "RoleId", "RoleName").ToList();
roles.Insert(0, new SelectListItem());
ViewBag.Roles = new SelectList(roles, "Value", "Text");
}
示例11: Edit
public ActionResult Edit([Bind(Include = "Id,StartTime,EndTime,DepartmentId,GroupId")] Schedule schedule)
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
var currentUser = userManager.FindById(User.Identity.GetUserId());
if (ModelState.IsValid && User.Identity.IsAuthenticated)
{
if (schedule.Id == 0)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Schedule dbSchedule = db.Schedules.Find(schedule.Id);
if (dbSchedule == null)
{
return HttpNotFound();
}
if (dbSchedule.Department.Bosses.Contains(currentUser) || (dbSchedule.Group != null && dbSchedule.Group.Department.Bosses.Contains(currentUser)))
{
db.Entry(dbSchedule).State = EntityState.Detached;
db.Entry(schedule).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index", "Schedules", new { id = schedule.DepartmentId });
}
else
{
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
}
}
ViewBag.DepartmentId = new SelectList(db.Departments.ToList().Where(q => q.Bosses.Contains(currentUser)).ToList(), "Id", "Name", schedule.DepartmentId);
var groups = new SelectList(db.DepartmentGroups.ToList().Where(q => q.Department.Bosses.Contains(currentUser)).ToList(), "Id", "Name", schedule.GroupId).ToList();
groups.Insert(0, new SelectListItem() { Value = "", Text = "All" });
ViewBag.GroupId = groups;
return View(schedule);
}
示例12: SelectListTextValue
public static SelectList SelectListTextValue(IEnumerable items, string valueField, string textField, string nullText, string nullTextValue)
{
var list = new SelectList(items, valueField, textField).ToList();
if (nullText != null) list.Insert(0, new SelectListItem { Text = nullText, Value = nullTextValue });
return new SelectList(list, "Value", "Text");
}
示例13: GetType
private async Task GetType(int? RoomTypeId,int WaitingListStatusId)
{
var roomtypes=await _RoomTypeRepository.GetAllEnabled();
List<SelectListItem> items = new SelectList(roomtypes, "Id", "Name",(RoomTypeId!=null) ? RoomTypeId.Value: 0).ToList();
items.Insert(0, (new SelectListItem { Text = "Any", Value = "0" }));
ViewBag.RoomTypeId = items;
var list = await _WaitingListStatusRepository.GetAllEnabled();
ViewBag.WaitingListStatusId = new SelectList(list.OrderBy(a=> a.Id), "Id", "Name", WaitingListStatusId);
}
示例14: LlenarControles
private void LlenarControles()
{
var provedores = new SelectList(Uow.Proveedores.Listado(), "ProveedorId", "Nombre").ToList();
provedores.Insert(0, new SelectListItem());
ViewBag.Proveedores = new SelectList(provedores, "Value", "Text");
var kioscos = new SelectList(Uow.MaxiKioscos.Listado(), "MaxiKioscoId", "Nombre").ToList();
kioscos.Insert(0, new SelectListItem());
ViewBag.MaxiKioscos = new SelectList(kioscos, "Value", "Text");
}
示例15: Edit
public ActionResult Edit(int id = 0)
{
ImageDetail imgdtls = db.ImageDetails.Find(id);
if (imgdtls == null)
{
return HttpNotFound();
}
ViewBag.Categories = new SelectList(db.Categories, "CategoryId", "CategoryName", imgdtls.CategoryId);
List<SelectListItem> items = new SelectList(db.Artists, "ArtistsId", "ArtistsName", imgdtls.ArtistId).ToList();
items.Insert(0, (new SelectListItem { Text = "- Select Artist -", Value = "0" }));
ViewBag.Artist = items;
// ViewBag.Artist = new SelectList(db.Artists, "ArtistsId", "ArtistsName", imgdtls.ArtistId);
return View(imgdtls);
}