I’m trying to pass the selected value of a DropDownList to a new controller method. However, in the controller, leagueKey is always coming back null. The drop down list is populating with values.
If I change new { leagueKey = Model.SelectedLeagueKey} to new {leagueKey = "test"} the controller correct receives the “test” value. It appears that the DropDownList isn’t binding the selected value to Model.SelectedLeagueKey.
Model
public Dictionary<string, string> Leagues { get; set; }
public string SelectedLeagueKey { get; set; }
View
<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)
Controller
public ActionResult AddTeam(LTEDContext context, string leagueKey)
{
//Do something with leagueKey here
return View();
}
Your view send you the SelectedLeagueKey parameter according to
Try to use the next code in a view:
}
and the next one in controller: