本文整理汇总了C#中System.Web.Mvc.SelectList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SelectList.Add方法的具体用法?C# SelectList.Add怎么用?C# SelectList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.SelectList
的用法示例。
在下文中一共展示了SelectList.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CategoryCreate
public ActionResult CategoryCreate()
{
var user = db.dt_user.FirstOrDefault();
if (Session["personel_id"] == null)
return RedirectToAction("Default", "Home");
else
{
int personel_id = Convert.ToInt32(Session["personel_id"]);
user = db.dt_user.Where(a => a.state == 1 && a.ID == personel_id).FirstOrDefault();
if (user == null)
return RedirectToAction("Default", "Home");
ViewBag.userName = user.name + " " + user.surname;
}
List<SelectListItem> listCategory = new SelectList(db.dt_category.ToList().Where(a => a.state == 1 && a.company_id == user.company_id), "ID", "name").ToList<SelectListItem>();
SelectListItem it = new SelectListItem();
it.Text = "Üst Kategori";
it.Value = "0";
listCategory.Add(it);
ViewBag.upCategoryID = listCategory.ToList();
return View();
}
示例2: _EditSearchedTerms
public ActionResult _EditSearchedTerms(long id, string term, string searchTypeCode)
{
IEnumerable<ISearcher> searchers = SearcherFactory.GetDisplaySearchers();
if (searchers != null)
{
List<SelectListItem> itemList = new SelectList(searchers.Select(n => new { text = n.Name, value = n.Code }), "value", "text", searchTypeCode).ToList();
bool selectedGlobal = false;
if (searchTypeCode == SearcherFactory.GlobalSearchCode)
{
selectedGlobal = true;
}
itemList.Add(new SelectListItem { Text = SearcherFactory.GlobalSearchName, Value = SearcherFactory.GlobalSearchCode, Selected = selectedGlobal });
ViewData["searchList"] = itemList;
}
ViewData["id"] = id;
return View();
}
示例3: DownloadReports
public ActionResult DownloadReports()
{
var data = db.TeamReports.DistinctBy(t => t.Round);
var i = new SelectList(data, "Round", "Round").ToList();
i.Add(new SelectListItem { Text = "全部报告", Value = "" });
ViewBag.List = i;
return View();
}
示例4: 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();
}
示例5: 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();
}
示例6: EditarAsignacion
// GET: Curso/EditarAsignacion/5
public ActionResult EditarAsignacion(int? id)
{
if (Request.UrlReferrer != null)
{
ViewBag.returnUrl = Request.UrlReferrer.ToString();
}
else
{
ViewBag.returnUrl = null;
}
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Group grupo = db.Groups.Find(id);
if (grupo == null)
{
return HttpNotFound();
}
/* Se obtiene la lista de profesores */
List<SelectListItem> vSelectList = new SelectList(db.Professors.OrderBy(p => p.Name), "ID", "Name").ToList();
SelectListItem selListItem = new SelectListItem() { Value = "0", Text = "Sin asignar" };
vSelectList.Add(selListItem);
ViewBag.Profesores = vSelectList;
return View(grupo);
}