2 回答
TA贡献1799条经验 获得超8个赞
您遇到的问题与没有值被发送到控制器的事实有关。以下 :
<option>@station.Name</option>
应该 :
//Assuming that your station class has an id
<option value = "@station.id">@station.Name</option>
你也可以这样做:
<select id="stationId" asp-for="stationId" asp-items=@(new SelectList(Model.Stations, "stationId", "Name")) class="form-control"></select>
TA贡献1789条经验 获得超10个赞
您也可以为此使用 Razor,我发现它有助于跟踪您在做什么:
@Html.DropDownListFor(m => m.StationId, --Value will be assigned to this variable
new SelectList(
Model.Stations,
"stationId",
"Name"), --List of values will come from here
"-Select Station-", --The default value
new {id="stationId",class="Form-control" } -- Attributes you would assignin HTML
)
- 2 回答
- 0 关注
- 123 浏览
添加回答
举报