I've tried a few different approaches. I'm not sure why but my SelectList/DropDown is empty. It shows no data. I'm not sure where I am going wrong.
I have an ASP.NET Core App. Entity Framework Core. Db First. I am using a repository pattern.
Here is my Model Class
public partial class Commodity
{
public Guid Oid { get; set; }
public string Code { get; set; }
}
This is my Interface:
interface ICommodityRepository
{
IEnumerable<Commodity> GetAll();
}
My Repository:
public class CommodityRepository : ICommodityRepository
{
private ltgwarehouseContext context;
public CommodityRepository()
{ }
public IEnumerable<Commodity> GetAll()
{
return context.Commodity.ToList();
}
}
My Controller:
public class CommoditiesController : Controller
{
static readonly CommodityRepository commodities = new CommodityRepository();
public CommoditiesController(CommodityRepository commodities)
{ }
// GET: /<controller>/
public IEnumerable<Commodity> CommoditiesList()
{
return commodities.GetAll();
}
}
This is my View/HTML Markup:
@model Lansing.BasisMap.Domain.Models.Commodity
<li><select asp-for="@Model.Code" asp-controller="Commodities" asp-action="CommoditiesList"></select> </li>