0

I have this function to add a row in a table and I need a drop-down list in the first cell with value that are on database. I tried with this: td1.innerHTML = "@Html.DropDownList("SubTipologia", lista)"; But does not work. Can you help me? Below there is the he function:

function aggiungiRiga(my_table) {
    var tbody = document.getElementById(my_table).getElementsByTagName("tbody")[0];
    var colonne = document.getElementById(my_table).getElementsByTagName('th');
    var row = document.createElement('tr');
    var td1 = document.createElement("td");
    td1.innerHTML = "<div>@Html.DropDownList("SubTipologia", lista)</div>";
    var td2 = document.createElement("td");
    td2.contentEditable = true;
    td2.innerHTML = "<input type=text placeholder='Volume'>";
    var td3 = document.createElement("td");
    td3.contentEditable = true;
    td3.innerHTML = "<input type = text placeholder = 'Volume al m&sup3'>";
    var td4 = document.createElement("td");
    td4.contentEditable = true;
    td4.innerHTML = "<input type=text placeholder='Valore Totale'>";
    var td5 = document.createElement("td");
    td5.innerHTML = "<button type=button class='btn btn -default btn - sm'><span class='glyphicon glyphicon-trash'></span></button >";
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    tbody.appendChild(row);
}
Ivan-San
  • 771
  • 1
  • 5
  • 22

1 Answers1

0

As I can see, you try to run server-side code on client (browser).

Browser doesn't khow about Razor or Html helper. So you need to use HTML instead of @Html.DropDownList("SubTipologia", lista) like this:

td1.innerHTML = "<div><select id='SubTipologia'></select></div>";

And then you can add items to <select> e.g. like here.