为什么枚举值没有显示在视图中

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

我想在主管批准后允许用户下载报告。目前,我正在使用经理帐户,他可以在其中检查许多报告并将其状态更改为已验证或拒绝,但我不明白为什么报告状态枚举列表未显示,即使它显示在控制台。

HTML code

型号:

public class Report
{
    public int ID { get; set; }
    [Display(Name = "Report Name")]
    public string reportName { get; set; }
    public virtual User reportManager { get; set; }
    [Display(Name = "State")]
    public ReportState reportState { get; set; }
    public byte[] reportData { get; set; }
}

public enum ReportState
{
    Accepted,
    Pending,
    Denied
}

控制器:

public async Task<IActionResult> Index()
    {
        ViewBag.Reports = await _context.Reports.ToListAsync();

        ViewBag.ReportStates = new SelectList(Enum.GetNames(typeof(ReportState)));

        return View();
    }

@model variable_pay_system.Models.Report

@{ 
   ViewData["Title"] = "Reports";
}

<div class="container">
<h5>Reports</h5>
<table>
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.reportName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.reportState)
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (Report report in ViewBag.Reports)
        {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => report.reportName)
            </td>
            <td>
                <select asp-for="@report.reportState" asp-items="Html.GetEnumSelectList<ReportState>()"></select>
            </td>
        </tr>
        }
    </tbody>
</table>
c# model-view-controller asp.net-core-mvc
2个回答
0
投票

好吧,问题是因为我最后错过了这段代码。

<script>
$(document).ready(function () {
    $('select').formSelect();
});

0
投票
<script>
$(document).ready(function () {
    $('select').formSelect();
});
</script>
© www.soinside.com 2019 - 2024. All rights reserved.