我的报告显示了包含以下列的列表:
A key column
A dropdown list showing a list of possible status
A title
这是剃刀代码:
@foreach (AdminSummary adminSummary in @Model.AdminSummaries) {
index++;
<div class="rep_tr0">
<div class="rep_td0" id="rk_@(index)">@adminSummary.RowKey</div>
<div class="rep_td0"><a href="/Administration/Products/Edit?&ac=@Model.Meta.AccountID&pr=@Model.Meta.ProductID&pa=@adminSummary.RowKey">Edit</a></div>
<div class="rep_td0"><a href="/Administration/Products/Delete?&ac=@Model.Meta.AccountID&pr=@Model.Meta.ProductID&pa=@adminSummary.RowKey">Delete</a></div>
<div class="rep_td0">@Html.DropDownListFor(??, ??)</div>
</div>
}
我也有以下课程:
public static class AdminStatusReference
{
public static IEnumerable<SelectListItem> GetAdminStatusOptions()
{
return new[]
{
new SelectListItem { Value = "1", Text = "Released" },
new SelectListItem { Value = "2", Text = "Review" },
new SelectListItem { Value = "3", Text = "New" }
};
}
}
我不确定如何将这些链接起来。我知道在模型中我可以存储列表 状态选项如下:
vm.StatusList = GetAdminStatusOptions();
但是如何创建下拉列表呢?我对DropDownList和的所有选项都非常困惑 DropDownListFor。我应该使用哪个以及如何发送状态列表?
答案 0 :(得分:1)
我不确定如何将它们联系起来。
这取决于模型的外观。
但这是你能做的:
@for (var index = 0; index < Model.AdminSummaries.Count; index++)
{
<div class="rep_tr0">
<div class="rep_td0" id="rk_@(index)">
@Model.AdminSummaries[index].RowKey
</div>
<div class="rep_td0">
@Html.DropDownListFor(
x => x.AdminSummaries[index].Status,
AdminStatusReference.GetAdminStatusOptions()
)
</div>
<div class="rep_td0">
@Model.AdminSummaries[index].Title
</div>
</div>
}