I've inherited some code and need to fix a number of bugs. One of which is a drop down list is having a 'selected' attribute set on a select html list. I can see from the code that this is set in a razor @Html.DropDownList:
@Html.DropDownList("makeId", vehicles.Makes, "Make..",
new { @class = "form-control footer-select", @id = "_man" })
In the HTML then this renders a select list:
<select class="form-control footer-select" id="_man" name="makeId"><option value="">Make..</option>
<option selected="selected" value="Alfa Romeo">Alfa Romeo</option>
<option value="Audi">Audi</option>
<option value="BMW">BMW</option>
<option value="Citroen">Citroen</option>
<option value="DS">DS</option>
<option value="Fiat">Fiat</option>
<option value="Ford">Ford</option>
<option value="Honda">Honda</option>
<option value="Hyundai">Hyundai</option>
<option value="Infiniti">Infiniti</option>
<option value="Jaguar">Jaguar</option>
<option value="Jeep">Jeep</option>
<option value="Kia">Kia</option>
<option value="Lamborghini">Lamborghini</option>
<option value="Land Rover">Land Rover</option>
<option value="Lexus">Lexus</option>
<option value="Maserati">Maserati</option>
<option value="Mazda">Mazda</option>
<option value="Mercedes-Benz">Mercedes-Benz</option>
<option value="Mini">Mini</option>
<option value="Mitsubishi">Mitsubishi</option>
<option value="Nissan">Nissan</option>
<option value="Peugeot">Peugeot</option>
<option value="Porsche">Porsche</option>
<option value="Renault">Renault</option>
<option value="Seat">Seat</option>
<option value="Skoda">Skoda</option>
<option value="Ssangyong">Ssangyong</option>
<option value="Tesla">Tesla</option>
<option value="Toyota">Toyota</option>
<option value="Vauxhall">Vauxhall</option>
<option value="Volkswagen">Volkswagen</option>
<option value="Volvo">Volvo</option>
</select>
I'm trying to reset the selected value and have ensure that nothing is selected right before this call to @html.dropdownlist:
vehicles.Makes.ForEach(i => i.Selected = false);
Yet the page still renders with the selected attribute set to true! What is the best way I can diagnose what is setting this value as it is driving me crazy!
I can't see anywhere in the client side JS that this is being set and can't see where/how this is getting set on the server side either Thank you