Javascript 带有html输入控件的动态生成的表行在回发时消失

Javascript 带有html输入控件的动态生成的表行在回发时消失,javascript,jquery,asp.net-mvc,html,razor,Javascript,Jquery,Asp.net Mvc,Html,Razor,我使用jquery动态生成了一个带有html输入控件的表行 问题是当有回发时,它们就会消失 我怎样才能让他们留下来 Html: JQuery: var attribute_row = 1; function addattribute(){html = '<tbody id="attribute-row' + attribute_row + '">';html += ' <tr>';html += ' <td class="left">@Html.Tex

我使用jquery动态生成了一个带有html输入控件的表行

问题是当有回发时,它们就会消失

我怎样才能让他们留下来

Html:

JQuery:

var attribute_row = 1; function addattribute(){html = '<tbody id="attribute-row' + attribute_row + '">';html += '  <tr>';html += '    <td class="left">@Html.TextBoxFor(x=>x.AttributeName)<div class="validation-area">@Html.ValidationMessageFor(x => x.AttributeName)</div></td>';html += '    <td class="right"><input type="text" name="Attribute_SortOrder" id="Attribute_SortOrder"></td>';html += '    <td class="left"><a onclick="$(\'#attribute-row' + attribute_row + '\').remove();" class="button">-</a></td>';html += '  </tr>';html += '</tbody>';$('#attribute tfoot').before(html);attribute_row++;$('#Attribute_Count').val(attribute_row);}
我解决了这个问题

@for (var i = 0; i < Model.Attribute_Count; ++i)
                        {
                            <tbody id="attribute-row">
                                <tr>
                                    <td class="left">

                                        @Html.TextBoxFor(x => x.AttributeName[i])
                                        <div class="validation-area">
                                            @Html.ValidationMessageFor(x => x.AttributeName[i])
                                        </div>
                                    </td>
                                    <td class="right">@Html.TextBoxFor(x => x.Attribute_SortOrder[i])</td>
                                    <td class="left"><a onclick="$('#attribute-row' + i).remove();" class="button">-</a></td>
                                </tr>
                            </tbody>
}

谢谢

您必须执行ajax回发,这样页面就不会重新加载这是因为新行没有存储。因此,当您进行回发时,您的行将丢失。您需要存储一些信息,以便页面重新加载它们。你可以用多种方法来做这件事。例如,每次使用jquery添加新行时,您都可以向服务器发送帖子,以存储有关新行的信息。一个小样本或例子会有所帮助。
@for (var i = 0; i < Model.Attribute_Count; ++i)
                        {
                            <tbody id="attribute-row">
                                <tr>
                                    <td class="left">

                                        @Html.TextBoxFor(x => x.AttributeName[i])
                                        <div class="validation-area">
                                            @Html.ValidationMessageFor(x => x.AttributeName[i])
                                        </div>
                                    </td>
                                    <td class="right">@Html.TextBoxFor(x => x.Attribute_SortOrder[i])</td>
                                    <td class="left"><a onclick="$('#attribute-row' + i).remove();" class="button">-</a></td>
                                </tr>
                            </tbody>
}