MVC3 DropDownListFor selected value does not reset if I set the Id
- by BarryFanta
I've read a lot of posts on here regarding the dropdown selected value issues (not showing etc etc...) but mine is the opposite problem.
I want the drop down to always reset after the view is returned after a button submits the page through the controller action. So how I've structured it all works but is it possible to reset the dropdown list each time? I can't find a way to do it and I've tried a lot of ways, believe me.
My View:
@Model.PspSourceModel.PayAccount.PaymentProviderId
<br />
@Html.DropDownListFor(
x => x.PspSourceModel.PayAccount.PaymentProviderId,
new SelectList(Model.PspSourceModel.PaymentProviders, "Value", "Text", "-- please select --"),
"-- please select --"
My Controller:
// I've tried forcing the selected value id here - doesn't effect the dropdownlist still?
pspVM.PspSourceModel.PayAccount.PaymentProviderId = 1;
return (View(pspVM));
My Webpage shows:
1 (the id I set in the Action)
dropdownlist with the id=6 or whatever value was chosen prior to submitting the form.
From the questions and answers on SO and the wider web I thought the dropdownlist seems tied to the id you choose but how do I override that to reset the dropdown to 'please select' each time?
Thanks in advance.