using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace InnovaApp.Portals.MVC4Portal.Models { public class DropDownListModel : _Models_Base { public int MyChoice { get; set; } public IEnumerable<SelectListItem> MyList { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using InnovaApp.Portals.MVC4Portal.Models; using INNOVACALL.Framework.Common.MVCHelpers; using InnovaApp.Layers.DataLayer; using InnovaApp.Layers.ResourcesLayer.Properties; namespace InnovaApp.Portals.MVC4Portal.Controllers { public class DropDownListController : _Controllers_Base<DropDownListModel> { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { eMethodBase = "InnovaApp.Portals.MVC4Portal.Controllers.DropDownListController"; specificCssCollection = new string[] { "_FormCommon.css", "Views/DropDownList.css" }; specificJSCollection = null; dynamicJSCollection = new string[] { "/ScriptsG/inoDropDownList.js" }; specificJqueryJSCollection = new string[] { "InnovacallJS/DropDownList/DropDownList.js" }; toAddToDocumentReady = null; toAddToFileDocumentReady = null; externalCSS = null; base.Initialize(requestContext); } [HttpGet, CacheManager(enCacheMode.NoCache)] //Manage your cache public ActionResult Index() { //NEVER USES VIEW BAG AGAIN ! //ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application."; { using (DataRepositories _dataContext = new DataRepositories()) { base.InitView( Resources.View_Home_PageTitle, string.Empty, specificCssCollection, specificJSCollection, dynamicJSCollection, specificJqueryJSCollection, toAddToDocumentReady, toAddToFileDocumentReady, externalCSS, _dataContext); ContentData.MyChoice = 1; ContentData.MyList = _dataContext.InnoAppUser_Rep.GetAll().OrderBy(x => x.Username).Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Username, Selected = false }).AsEnumerable(); } return View(ContentData); } } } }
@model InnovaApp.Portals.MVC4Portal.Models.DropDownListModel @Html.DropDownListFor(m => m.MyChoice, Model.MyList)