在我的项目中,我想基于BlockID从db中提取所有字段,设施,坦克。对于每个类别,如田地,设施,坦克,我准备了局部视图。当我运行解决方案时,我只能在下拉控件中检索与块相关的字段。我想显示所有字段'部分视图中与该块相关的数据,并在下拉列表中填充它们。我可以在.cshtml文件中看到数据,但我无法在UI上呈现它们。请帮帮我。
//控制器操作
public PartialViewResult FieldsOfBlock(long blockid)
{
FacilityModel bkvm = new FacilityModel();
var fields = bkvm.FieldList(blockid); // comes from backend
ViewBag.Data = fields;
return PartialView("_PartialField");
}
// PartialView
@model List<ABC.Models.Field>
@{
var data = ViewBag.Data as List<ABC.Models.Field>;
}
<div class="table-responsive col-lg-12 margintop20">
<table class="table table-bordered table-hover" id="myTableDataField">
<thead>
<tr>
<th>Field Name</th>
</tr>
</thead>
<tbody>
@{
if(data.Count!=0)
{
foreach (var item in data)
{
<tr>
<td>@item.Name</td>
</tr>
}
}
}
</tbody>
</table>
</div>
提前致谢。