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
Published on 21-Mar-2018 07:59:06
Advertisements