C# 和实体框架 - 我需要在 select 中显示名称而不是 id

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

我使用实体框架、数据库优先方法创建了一个应用程序,并使用脚手架生成页面。它在选择中显示表 ID,而不是名称。

enter image description here

enter image description here

c# entity-framework 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.