开发者

ASP.NET MVC 3 Dropdownlist Helper renders name incorrectly

I am using the HTML helper for Dropdownlist in the following manner:

<%= Html.DropDownList("State", new SelectList(states, Model)) %>

The control renders fine, with the state items as expected. However, the id and name of the control are not rendering correctly. Instead of开发者_JAVA技巧 name="state" and id="state" I get name="State.State" and id="State_State".

As a result my posted model comes with the State field empty and of course my code fails.

What could cause this to happen, and how might I try to resolve it?

thanks!


<%= Html.DropDownList("State", new SelectList(states, "Id", "Name")) %>

where Id and Name must be valid properties of element in the states collection you are binding to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜