mvc 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: razor dropdownlistfor

@using MyMVCApp.Models

@model Student

@Html.DropDownListFor(m => m.StudentGender, 
            new SelectList(Enum.GetValues(typeof(Gender))), 
            "Select Gender")

Tags:

Html Example