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 關注
- 141 瀏覽
添加回答
舉報