Html.DropDownListFor Selected=true 在索引视图中自动重置



我在 mvc 页面中通过模态绑定@html.DropdownListFor控件。

我的代码如下 cshtml 页面,

@Html.DropDownListFor(a => a.stateId, Model.statelist, new { @id = "StateList", @class = "form-control" })

在上面的模型中,状态列表的类型为List<SelectListItem>

我通过调试代码检查了 Model.statelist 有第 2 项 Selected=true。

但是在浏览器上呈现页面后,选定项转到第一项。

任何人都可以建议我。

我认为您需要进行以下更改。我确实注意到,对于第一个参数,您使用了"a",而对于第二个参数列表,您使用了"模型"。

@Html.DropDownListFor(model => model.stateId, model.statelist, new { @id = "StateList", @class = "form-control" })

最新更新