当在 CRUD 中创建时显示其他列然后是外键
When Create in CRUD show other column then Foreign Key
很确定你们会知道我是
通过查看我的问题,这方面相当新。
因此,当我从 CRUD 创建时,我得到外键 ID 值,这是可以理解的,我的外键是等级 ID,但我想显示用户不是 ID,而是等级,它可以是 A、B、C,它存储在另一个列中,同时仍然保存外键用户单击创建时的密钥 ID
enter image description here
对不起英语不好。
如果你想让下拉列表显示的是Grade value而不是Grade id,你可以试试Using ViewBag to transfer the list of items
public IActionResult Create()
{
//using viewbag
ViewBag.Country = new SelectList(_context.Country, "Id", "CountryName");
return View();
}
并在视图中
<select asp-for="CountryId" class="form-control" asp-items="ViewBag.Country"></select>
更多Select Tag Helper绑定值的方法,可以参考
很确定你们会知道我是 通过查看我的问题,这方面相当新。 因此,当我从 CRUD 创建时,我得到外键 ID 值,这是可以理解的,我的外键是等级 ID,但我想显示用户不是 ID,而是等级,它可以是 A、B、C,它存储在另一个列中,同时仍然保存外键用户单击创建时的密钥 ID enter image description here 对不起英语不好。
如果你想让下拉列表显示的是Grade value而不是Grade id,你可以试试Using ViewBag to transfer the list of items
public IActionResult Create()
{
//using viewbag
ViewBag.Country = new SelectList(_context.Country, "Id", "CountryName");
return View();
}
并在视图中
<select asp-for="CountryId" class="form-control" asp-items="ViewBag.Country"></select>
更多Select Tag Helper绑定值的方法,可以参考