需要一些帮助来修复通过 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>
截图
谢谢