How to bind dynamic table's from html to asp.net Razor Pages model

Viewed 376

I am creating a Razor-Pages application and i need to bind a dynamic HTML table with some items into a List in the model, so i have the following codes:

Asp.net Code

public class SolicitacaoDescarteColeta
    {
        public int SolicitacaoDescarteColetaID { get; set; }
        public int IDDescartador { get; set; }
        public int IDEcoponto { get; set; }
        public string TipoDoMaterial { get; set; }

        public IList<ItemDescarte> ItensDescarte { get; set; }

        public DateTime? DataDeEntrega { get; set; }
    }


public class ItemDescarte
{     
    public int ItemDescarteID { get; set; }
    public string TipoDoItem { get; set; }
    public string DescricaoDoItem { get; set; }

    public int SolicitacaoDescarteColetaID { get; set; }
    public SolicitacaoDescarteColeta SolicitacaoDescarteColeta { get; set; }

}

Razor Pages cshtml

   <div class="col-md-4">
       <label class="control-label">Tipo de item</label>
           <select id="tipo_item" class="form-select form-control dropdown" required>
               <option id="" selected value="">Selecione</option>
               <option class="itens_reciclaveis" value="Plástico">Plastico</option>
               <option class="itens_reciclaveis" value="Metal">Metal</option>
               <option class="itens_reciclaveis" value="Vidro">Vidro</option>
               <option class="itens_reciclaveis" value="Papel">Papel</option>                               
           </select>
    </div>

   <div class="col-md-7">
       <label class="control-label">Descrição do Item</label>
          <input type="text" name="" id="item_descricao" class="form-control" required>
           <i class="bi bi-plus-square"></i>
   </div>


     <table class="table table-striped" id="tabela_itens">
            <thead>
                <tr>
                    <th scope="col">Nº Item</th>
                    <th scope="col">Tipo</th>
                    <th scope="col">Descrição</th>
                </tr>
            </thead>
            <tbody id="tabela_itens_body">
            </tbody>
      </table>

Dynamic table show: AddItems

I am still new at asp.net, i want each line of my table binding a new item in my ItensDescarte List, is there some way i can do this?

Ps.: Forgive me for my bad english tho

0 Answers
Related