Choose which option is selected on pageload of razor Html.DropDownListFor() in HTML?

HTMLWeb DevelopmentFront End Technology

Shorthand is used to decide which option is selected on pageload of razor Html.DropDownListFor(). You can try to run the following code snippet −

// return Boolean value
@Html.DropDownListFor(m => m.Valeur,
new List< SelectListItem > { //new list item list item1 is generated
new SelectListItem { Value = "0" , Text = "Show", Selected = Model.Valeur == 0 },
new SelectListItem { Value = "1" , Text = "Hide", Selected = Model.Valeur != 0 },
}, new { @class = “selectnew" })
raja
Updated on 04-Mar-2020 06:13:12

Advertisements