I have two dropdownlists.
The first one automatically gets loaded with all the staff in it. Then the 2nd one gets populated depending on first one's value.
However, how can I make it so that in the view, IF there are parameters in the URL, the code automatically select the matching values in the dropdownlists?
so if the url is: https://localhost:44350/?Staff=BillGates&StaffCode=12345
Dropdownlist 1 will contain Bill Gates and Dropdownlist 2 will contain 12345.
<div class="form-group">
@Html.LabelFor(model => model.staff, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.staff, (IEnumerable<SelectListItem>)ViewBag.StaffList, "Select", new { @class = "form-control", onchange = "selected()" })
@Html.ValidationMessageFor(model => model.staff, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.staffcode, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.staffcode, Enumerable.Empty<SelectListItem>(), "Select", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.staffcode, "", new { @class = "text-danger" })
</div>
</div>
Thanks