【发布时间】:2019-01-20 11:08:10
【问题描述】:
我被困在这一部分上。当我进行搜索时,所有出现的都是带有控制器、视图包和 MVC 中的其他示例的示例。
我正在尝试从数据库中填充下拉列表。到目前为止,这是我的代码
Category.cs
public class Category
{
[Key]
public int CategoryID { get; set}
public string CategoryName { get; set; }
}
Editor.cshtml.cs
public class Editor : PageModel
{
private readonly DatabaseContext _context;
public Editor(DatabaseContext databasecontext)
{
_context = databasecontext;
}
public void OnGet()
{
List<Category> categoryList = new List<Category>();
categoryList = (from Category in _context.Category select Category).ToList();
categoryList.Insert(0, new Category { CategoryID = 0, CategoryName = "Select" });
}
}
将下拉列表附加到我的 Razor 视图页面的下一步是什么?
【问题讨论】:
标签: razor asp.net-core asp.net-core-2.0