How can I set the selected value of a Html.DropDownListFor? I've been having a look online and have seen that it can be achieved by using the fourth parameter so like the below:
@Html.DropDownListFor(m => m, new SelectList(Model, "Code", "Name", 0), "Please select a country")
My select list then display like this:
<select id="ShipFromCountries" name="ShipFromCountries">
<option value="">Please select a country</option>
<option value="GB">United Kingdom</option>
<option value="US">United States</option>
...
</select>
But for some reason United Kingdom remains selected but I want "Please select a country" to be selected.
Anyone know how I can achieve this?
EDIT
I've updated my code as there was a slight change in functionality however still seem to be encountering this problem. This is what is in my view:
@Html.DropDownListFor(n => n.OrderTemplates, new SelectList(Model.OrderTemplates, "OrderTemplateId", "OrderTemplateName", 1), "Please select an order template")
1
is the Id of the option
that I want selected, I have also tried with the text of the option
but that also does not work.
Any ideas?