razor dropdownlist code example
Example 1: how to creat dropdownlist in razor page using select list item
@Html.DropDownList("ReportType", new List<SelectListItem>{
new SelectListItem { Text = "Summary", Value = "summary" },
new SelectListItem { Text = "Detail", Value = "detail" }
}, "Select Report Type", new { @class = "form-control", @required = "required" })
Example 2: generate a dropdown list from array data using razor .net mvc
@Html.DropDownList("myList", ViewBag.myList as SelectList)
Example 3: razor dropdownlistfor
@using MyMVCApp.Models
@model Student
@Html.DropDownListFor(m => m.StudentGender,
new SelectList(Enum.GetValues(typeof(Gender))),
"Select Gender")