下拉框如何从数据库取数据
时间:2019-06-03 18:22:01
收藏:0
阅读:517
先获取List
在Controller里面写好获取List,然后通过ViewBag传到视图
ViewBag.testList = _testBll.GettestList();
这样获取到了List集合
视图处理
首先,接收一下
@{
var testList = ViewBag.testList;
}
然后,写一个HTML标签,使用select标签,value是id,显示的是name
<th>测试下拉框</th>
<td data-title="测试下拉框">
<select id="test" name="test" style="width: 150px; height: 23px;">
@foreach (test item in testList)
{
<option selected="selected" value="@item.id">@item.Name</option>
}
</select>
</td>
原文:https://www.cnblogs.com/yunquan/p/10968974.html
评论(0)