数据库中的 ViewBag 值显示为白色

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

需要一些帮助来修复通过 ViewBag 下拉绑定从数据库中提取的值。

结果显示为白色,这意味着数据在视图中不可见。

这是我的代码

班级

[钥匙] public int countryId { 得到;放; }

public IEnumerable countryName { get;放; }

public string countryCode { get;放; }

控制器

public ActionResult DropDown()
        {

            using (Db db = new Db())
            {
                ViewBag.countryVal = new SelectList(db.Countries.ToList(), "countryName", "countryName");

                return View();
            }
        }

查看

<table>
    <tbody>
    <td>
        @Html.DropDownList("countryVal", "Select")
    </td>
    </tbody>
</table>

截图

非常感谢任何帮助。

谢谢

asp.net-mvc viewbag
© www.soinside.com 2019 - 2024. All rights reserved.