问题描述
我不知道这是否与DropDownListFor分机或什么错误,但我们有以下几点:
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")
然而,当我在视图模型参数更改MyParam到MyParam2和更新我查看使用MyParam2参数相反,它会选择给MyParam2价值的正确选择项目。之前,它不会在参数名字是MyParam。
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.
有没有其他人碰到了呢?这是MVC 3中的错误,或者这是我的一个坏的实施?
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,
该网址有键myparam将queryString,因为名字是一样的属性名称和URL时调用,将反对myparam添加的ModelState值。
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]将myvalue的。
ModelState["myparam"] will be "myvalue".
因此,当页面加载的下拉从下拉菜单中选择myvalue的。
So when the page is loaded the dropdown will select "myvalue" from drop down.
这篇关于ASP.NET MVC 3 - DropDownListFor失败时,URL参数还以相同的名称作为视图模型参数存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!