C# -『ASP.MVC 5 : DropDownList』

/*** * In BackEnd ***/ public ActionResult CourseDetail(string ID, string CourseName) { CourseModel objCourse = CoursetService.FetchSingleCourse(ID, CourseName); IEnumerable<string> CourseTime = CoursetService.FetchCourseTimeById( ID, CourseName ); ViewBag.CourseTime = ToListItem ( CourseTime ); return View( objCourse ); } /// <summary> /// IEnumerable<string> Convert to IEnumerable<SelectListItem> /// </summary> /// <param name="results"></param> /// <returns></returns> private IEnumerable<SelectListItem> ToListItem( IEnumerable<string> results ) { return results.Select(s => new SelectListItem ( ) { Value = s, Text= s} ); } /*** * In FrontEnd ***/ using ( Html.BeginForm ( "???", "???", FormMethod.Post ) ) { @Html.DropDownList( "CourseTime", ( IEnumerable<SelectListItem> ) ViewBag.CourseTime, new {@class = "form-control" } ) <input name="submit" type="submit" class="btn btn-primary btn-block" value="SelectCourseTime"></div> }
C# -『ASP.MVC 5 : DropDownList』

IEnumerable<string> Convert to IEnumerable<SelectListItem>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.