剃须刀页面选择列表不会填充



My Branch SelectList不会填充数据。查询确实返回了15条记录,但它们没有绑定到Select控件。有什么想法吗?

这是出现在asp项目的HTML页面结果中的内容,而不是项目。为什么会添加tp-asp项目System.Collections.Generic.List`1[Microsoft.AspNetCore.Mvc.Frendering.SelectListItem]

<select asp-items="System.Collections.Generic.List`1[Microsoft.AspNetCore.Mvc.Rendering.SelectListItem]"
asp-for="Branch"></select>

这是我的HTML Razor页面。

<h5 class="card-title">Choose Branch</h5>
<select id="selectBranches" asp-for="Branch" asp-items="@Model.Branches" disabled="enabled" class="custom-select"></select>

这是我的C#RazorPage。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SetpointIS.Models;
using SetpointIS.Models.Datawarehouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc.Rendering;
public class EditModel : PageModel
{
private DBContextVuPoint db;
public List<SelectListItem> Branches { get; set; }
public EditModel(DBContextVuPoint _db)
{
db = _db;
}
public void OnGet()
{
Branches = db.Branch.Select(a =>
new SelectListItem
{
Value = a.BranchId.ToString(),
Text = "(" + a.Abbreviation + ")" + a.Name
}).ToList();
}
}

asp-for中,您编写了Branch而不是"Branches">

最新更新