I am not sure if this is a bug with the DropDownListFor extension or what, but we had the following:
http://mydomain.com/path/page?myparam=myvalue
In my View Model I have the following:
public string MyParam { get; set; }
public List<SelectListItem> ParamOptions { get; set; }
When I do the following in my View it fails to select the correct value:
@Html.DropDownListFor(x => x.MyParam, Model.ParamOptions, "Select Value")
However, when I change the parameter ‘MyParam’ in my view model to ‘MyParam2’ and update my View to use MyParam2 parameter instead, it will select the correct option item given the value of MyParam2. Before it would not when the parameter name was MyParam.
Has anyone else ran into this? Is this a bug with MVC 3 or is this a bad implementation on my part?
What about the URL mentioned,
http://mydomain.com/path/page?myparam=myvalue
The url has a queryString with key “myparam”, since the name is same as property name and When the url is invoked it will add a ModelState value against “myparam”.
ModelState[“myparam”] will be “myvalue”.
So when the page is loaded the dropdown will select “myvalue” from drop down.