Following is my code which i am using to add new row with the html helpers in each td.
I am making a view of Bill Of Material in my application for which I need to have a structure where there are many children(ingredients) under a main parent(Main Material).
My approach is to have html helpers in the td and with the button click add row and add the children(ingredients).
I am not able to get a new row when i click the button in my following code. Please help and please suggest if there is any other proper approach for getting my Bill Of Material view done.
I am taking reference of this link .
$("#myButton").click(function () {
debugger;
// Create elements dynamically
var newRow = "<tr><td>'@Html.TextBoxFor(x => x.Id, new { @Value = "1" })'</td><td>'@Html.TextBoxFor(x => x.Name, new { @Value = "Abcd" })'</td></tr>";
alert(newRow);
// Add the new dynamic row after the last row
$('#aliasTable tr:last').after(newRow);
});
<h2>Index</h2>
<table id="aliasTable">
<tr>
<td>
@Html.TextBoxFor(Model => Model.Id, new { @Value = "1" })
</td>
<td>
@Html.TextBoxFor(Model => Model.Name, new { @Value = "Abcd" })
</td>
</tr>
</table>
<button id="myButton">Add New Row</button>