我正在尝试将 DropDownList 的选定值传递给新的控制器方法。但是,在控制器中,leagueKey
总是返回 null。下拉列表中填充了值。
如果我更改new { leagueKey = Model.SelectedLeagueKey}
为new {leagueKey = "test"}
控制器正确接收“测试”值。看来 DropDownList 没有将所选值绑定到Model.SelectedLeagueKey
.
模型
public Dictionary<string, string> Leagues { get; set; }
public string SelectedLeagueKey { get; set; }
看法
<div class="edit-field">
@Html.DropDownListFor(model => model.SelectedLeagueKey, new SelectList(Model.Leagues, "Key", "Value", Model.SelectedLeagueKey),"Select League")
</div>
@Html.ActionLink("Select League", "AddTeam", "Team", new { leagueKey = Model.SelectedLeagueKey}, null)
控制器
public ActionResult AddTeam(LTEDContext context, string leagueKey)
{
//Do something with leagueKey here
return View();
}