Model: namespace MVCWebApp.Models { public class Spices { public string Nice { get; set; } public int SelectSpiceId { get; set; } //selected spice id. public double Price { get; set; } } // used to popuplated the dropdownlist/select public class SpiceType { public int SpiceId { get; set; } public string SpiceName { get; set; } } } DataRepository: using MVCWebApp.Models; namespace MVCWebApp.Services { public interface IDataRepository { List GetSpices(); List GetSpiceTypes(); } public class DataRepository : IDataRepository { public List GetSpices() { return new List() { new Spices(){ SelectSpiceId= 102, Price = 2.73, Nice="Very Nice"}, new Spices(){ SelectSpiceId= 101,Price = 1.00, Nice="Nice"}, new Spices(){ SelectSpiceId=104,Price = 3.22, Nice="Very Nice"}, new Spices(){ SelectSpiceId= 103,Price = 0.23, Nice="Nice"}, }; } public List GetSpiceTypes() { return new List() { new SpiceType(){ SpiceId=101, SpiceName = "Parsley"}, new SpiceType(){ SpiceId=102, SpiceName = "Sage"}, new SpiceType(){ SpiceId=103, SpiceName = "Rosemary"}, new SpiceType(){ SpiceId=104, SpiceName = "Thyme"}, }; } } } Controller: using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using MVCWebApp.Models; using MVCWebApp.Services; using System.Diagnostics; namespace MVCWebApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; private readonly IDataRepository _datarepo; public HomeController(ILogger logger, IDataRepository dataRepository) { _logger = logger; _datarepo = dataRepository; } public IActionResult SpicesIndex() { var spices = _datarepo.GetSpices(); var spicestype = _datarepo.GetSpiceTypes(); ViewBag.SpiceList = new SelectList(spicestype, "SpiceId", "SpiceName"); return View(spices); } [HttpPost] public IActionResult SaveSpices(List spices) { return View(); } View: @model List @{ ViewData["Title"] = "SpicesIndex"; }

SpicesIndex

Create New

@for (var i= 0; i< Model.Count;i++ ) { }
Spice Price Nice