I have a report that shows a list with the following columns:
A key column
A dropdown list showing a list of possible status
A title
This is the razor code:
@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>
}
I also have the following class:
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" }
};
}
}
What I am not sure is how I can link these up. I know in the model I can store the list of
status options something like this:
vm.StatusList = GetAdminStatusOptions();
But how can I create the dropdownlist. I am very confused with all of the options of DropDownList and
DropDownListFor. Which should I be using and how can I send in the list of statuses?
This will depend on how the model looks like.
But here’s what you could do: