C# MVP - 我需要在 select 中显示名称而不是 id

问题描述 投票:0回答:1

我使用实体框架制作了一个应用程序,首先使用数据库,然后使用 scafolld 生成页面。它在选择中显示表 ID,而不是名称。

enter image description here

enter image description here

它在选择中显示表 ID,而不是名称。

c# entity-framework model-view-controller scaffolding scaffold
1个回答
0
投票

在控制器中:

ViewBag.BookTypes = new SelectList(bookTypes, "Id", "TypeName");

所见:

@Html.DropDownList("SelectedBookType", ViewBag.BookTypes as SelectList, "Select a Book Type", new { @class = "form-control" })

© www.soinside.com 2019 - 2024. All rights reserved.