excatmexy9997
New Member
My select list isn't selecting the default object being brought in through code.I first create my SelectList like so:\[code\] public SelectList CreateSelectList(object objSelected = null) { return new SelectList(GetAll().OrderBy(s => s.NumericalValue), "PeriodID", "Name", objSelected); }\[/code\]My objSelected gets filled with a Guid that's associated with the PeriodID.Inside my controller I define my viewbag variable to the new select list.\[code\] public ActionResult Edit(Guid id) { Classroom classroom = classroomRepository.GetByID(id); ViewBag.PeriodID = periodRepository.CreateSelectList(classroom.PeriodID); return View(classroom); }\[/code\]Then in my View here's how I'm displaying my SelectList:\[code\]<div class="control-group"> @Html.LabelFor(model => model.PeriodID, "Period", new { @class = "control-label" }) <div class="controls"> @Html.DropDownListFor(model => model.PeriodID, ViewBag.PeriodID as SelectList, String.Empty, new { @class = "span3" }) @Html.ValidationMessageFor(model => model.PeriodID) </div> </div>\[/code\]