This article describes how to use js to get the selected value from the drop-down box. The instance code is attached. If you need a friend, you can refer to the current requirements: in the drop-down box, if you want to select a franchisee to continue to select a school, if you select a platform administrator, you do not need to select a school. Hide the selected drop-down list.
Select the enumerated value:
////// Platform role ///Public enum AdministratorRole {[Display (Name = "platform administrator")] PlatformAdministrator = 1, [Display (Name = "franchisee")] JoiningTrader = 10}
Code:
@Html.LabelFor(x => x.AdministratorRole, new { @class = "col-sm-2 control-label" })
@Html.EnumDropDownListFor(x => x.AdministratorRole, new { @class = "form-control", onChange = "showSchool(this.value)", placeholder = Html.DisplayNameFor(x => x.AdministratorRole) })
@Html.ValidationMessageFor(x => x.AdministratorRole)
@Html.LabelFor(x => x.SchoolId, new { @class = "col-sm-2 control-label" })
@Html.DropDownListFor(x => x.SchoolId, Model.Schools, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.SchoolId) })
@Html.ValidationMessageFor(x => x.SchoolId)
Hide the school list first. style = "display: none" has the same effect. We use the onChange event in the drop-down box to execute the Set Method showSchool (). The parameter here is the value we selected, and this represents the AdministratorRole.
Js Code: