I'm trying to add a button to 'add new row' to the table in my mvc view.
First I tried this and it worked.
<script type="text/javascript">
$(document).ready(function () {
function addRow() {
var html = '<tr><td>' +
'<input type="text" id="Text1">' +
'</td><td>' +
'<input type="text" id="Text2">' +
'</td></tr>'
$(html).appendTo($("#table1 > tbody"))
};
$(".BtnAdd").click(addRow);
});
</script>
Then I had to change input type="text" to @Html.TextAreaFor()
So I tried this...but not working
<script type="text/javascript">
$(document).ready(function () {
function addRow() {
var html = '<tr><td>' +
'@Html.TextAreaFor(m => m.schedule1)' +
'</td><td>' +
'@Html.TextAreaFor(m => m.Schedule2)' +
'</td></tr>' +
$(html).appendTo($("#table1 > tbody"))
};
$(".BtnAdd").click(addRow);
});
</script>
Anyone please help me...Sorry if my way of presenting the problem is bad (new to .net)
Is there any other good way? (using for each loop etc)
Thanks