title: How can i fill a table with values from a dropdownlist in ASP.NET Core MVC
body: <p>I want to fill an html table with the selecteditem from a dropdownlist, I already passed the database data to this list, and I also get all the information of the selected value through an actionresult, so the thing I want is when I select an item, put it in the table, and do this every time I want so I can add various values at the same time. does anyone have any idea how to do it?</p>
  
  <p>This is my model</p>
  
  <pre><code>public partial class Producto
  {
      public int Id { get; set; }
      public string Nombre { get; set; }
      public string Descripcion { get; set; }
      public string Precio { get; set; }
  
      [NotMapped]
      public List &lt;Producto&gt; Listasnom { get; set; }
  
      [NotMapped]
      public IEnumerable &lt; SelectListItem &gt; ProductoListItems  
          {  
              get  
              {  
                  return new SelectList(Listasnom ?? new List&lt;Producto&gt;(), "Id", "Nombre"); 
              }  
          } 
  }
  </code></pre>
  
  <p>My controller</p>
  
  <pre><code>MyDbContext db = new MyDbContext();
  
         [HttpGet] 
          public ActionResult Index()
          {
              return View(db.Pedido.ToList());
          }
  
          public ActionResult Create()
          {    
              var lista = new Producto();    
              lista.Listasnom = db.Producto.ToList();
  
              return View(lista);
          }  
  
          [HttpPost]
          public ActionResult Create(Producto producto)
          {    
              var lista = new Producto();     
              lista.Listasnom = db.Producto.ToList();
  
              var emp = lista.Listasnom.Where(e =&gt; e.Id == producto.Id).FirstOrDefault();
  
              lista.Id = emp.Id;
              lista.Nombre = emp.Nombre; 
              lista.Precio = emp.Precio;
  
              return View(lista);                
          } 
  </code></pre>
  
  <p>and my view:</p>
  
  <pre><code>@model punto.Models.Producto
  
  &lt;form class="form-horizontal" method="post" action=""&gt;
          &lt;div class="box-body"&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label for="inputEmail3" class="col-sm-1 control-label"&gt;Producto&lt;/label&gt;
              &lt;div class="col-sm-10"&gt;
                         @Html.DropDownListFor(model =&gt; model.Id, Model.ProductoListItems, "Elegir Producto", new { @class = "form-control"}) 
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-info"&gt;Agregar&lt;/button&gt; 
          &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the table where I want to put the values</p>
  
  <pre><code>&lt;table id="example1" class="table table-bordered table-responsive"&gt;
              &lt;thead&gt;
              &lt;tr&gt; 
                  &lt;th&gt;Id&lt;/th&gt;                 
                  &lt;th&gt;Producto&lt;/th&gt;
                  &lt;th&gt;Precio&lt;/th&gt;
              &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                      &lt;tr&gt;
                          &lt;td&gt;@Html.DisplayFor(model =&gt; model.Id)&lt;/td&gt;
                          &lt;td&gt;@Html.DisplayFor(model =&gt; model.Nombre)&lt;/td&gt;
                          &lt;td&gt;@Html.DisplayFor(model =&gt; model.Precio) &lt;/td&gt;
                      &lt;/tr&gt; 
  &lt;/table&gt;
  </code></pre>
  
  <p>I don't have any idea how to do it, if someone can help me.</p>