来自 table 的下拉列表以将值保存在外键中

Drop Down list from table to save value in foreign key

我有两个表:Employer(ID(PK), Name) & student(ID, Name, Employer_ID(FK))

我使用下拉列表显示雇主姓名列表@Html.DropDownList("Employer_ID", null, htmlAttributes: new { @class = "form-control" })

但是从这里我想保存雇主的值而不是使用字符串。

这是您的清单。

ViewBag.ItemID = new SelectList(yourItemList, "ItemID", "ItemName"); 

@Html.DropDownList("ItemID", null, htmlAttributes: new { @class = "form-control" })

祝你好运。