ASP.NET MVC 3 - DropDownListFor Fails when URL Parameter Also Exists with Same Name as View Model Parameter

StackOverflow https://stackoverflow.com/questions/9416469

質問

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?

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top