I am currently trying to use taghelpers in asp.net 5. I want to use a select tag helper with a list from the ViewBag. Anything I put into the asp-for field gives me an error because it tries to pull it from the model which is IEnumerable instead of the view bag.
I want to replace this:
@model IEnumerable<InvoiceIT.Models.Invoice>
@using (Html.BeginForm())
{
<p>
@Html.DropDownList("Companies", String.Empty)
<input type="submit" value="Filter" class="btn btn-default" />
</p>
}
with this:
@model IEnumerable<InvoiceIT.Models.Invoice>
<form asp-controller="Invoice" asp-action="Index" method="post" class="form-horizontal" role="form">
<select asp-for="????" asp-items="ViewBag.Companies" class="form-control">
</select>
<input type="submit" value="Save" class="btn btn-default" />
</form>
Here is how I populate the select list in the controller:
ViewBag.Companies = new SelectList(await DbContext.Company.ToListAsync(), "CompanyID", "Name");