0

連絡先情報があり、ユーザーがいくつかの連絡先を追加して保存したい.つまり、連絡先ごとに連絡先情報をサーバーに送信したくないので、クライアントに保存し、[保存]ボタンをクリックした後、すべてどうすれば保存できますか? リストに追加して保存する方法は? 私のモデルクラスは次のとおりです。

    public System.Guid ContactId { get; set; }
    public string Tel { get; set; }
    public string Fax { get; set; }
    public string Mobile { get; set; }

とビューで:

            <% using (Html.BeginForm()) { %>
                <%: Html.ValidationSummary(true) %>
                                                    <div class="editor-label">
        <%: Html.LabelFor(model => model.Tel) %>
    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Tel) %>
                        <%: Html.ValidationMessageFor(model => model.Tel) %>
                    </div>

                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Fax) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Fax) %>
                        <%: Html.ValidationMessageFor(model => model.Fax) %>
                    </div>

                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Mobile) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Mobile) %>
                        <%: Html.ValidationMessageFor(model => model.Mobile) %>
                    </div>
            <% using (Html.BeginForm()) { %>
                <%: Html.ValidationSummary(true) %>
                                            <div class="editor-label">
            <%: Html.LabelFor(model => model.Tel) %>
        </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Tel) %>
                        <%: Html.ValidationMessageFor(model => model.Tel) %>
                    </div>

                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Fax) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Fax) %>
                        <%: Html.ValidationMessageFor(model => model.Fax) %>
                    </div>

                    <div class="editor-label">
                        <%: Html.LabelFor(model => model.Mobile) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.EditorFor(model => model.Mobile) %>
                        <%: Html.ValidationMessageFor(model => model.Mobile) %>
                    </div>
            <div class="demo">
                <button >
                    <span class="ui-button-text">Add to list</span></button>
            </div>
            <% List<Contact> list = (List<Contact>)ViewBag.ListContacts; %>
            <fieldset>
                <legend>Contacts</legend>
                <table>
                    <tr>
                        <th>
                            Tel
                        </th>
                        <th>
                            Fax
                        </th>
                        <th>
                            Mobile
                        </th>
                        <th>
                        </th>
                    </tr>
                    <% foreach (var itm in list)
                       { %>
                    <tr>
                        <td>
                            <%: Html.DisplayFor(f => itm.Tel) %>
                        </td>
                        <td>
                            <%: Html.DisplayFor(m => itm.Fax)%>
                        </td>
                        <td>
                            <%: Html.DisplayFor(m => itm.Mobile)%>
                        </td>
                        <td>
                            <%: Html.ActionLink("Delete","Delete",new {id= itm.ContactId}) %>
                        </td>
                    </tr>
                    <% } %>
                </table>
            </fieldset>
            <% } %>
            <% List<Contact> list = (List<Contact>)ViewBag.ListContacts; %>
            <fieldset>
                <legend>Contacts</legend>
                <table>
                    <tr>
                        <th>
                            Tel
                        </th>
                        <th>
                            Fax
                        </th>
                        <th>
                            Mobile
                        </th>
                        <th>
                        </th>
                    </tr>
                    <% foreach (var itm in list)
                       { %>
                    <tr>
                        <td>
                            <%: Html.DisplayFor(f => itm.Tel) %>
                        </td>
                        <td>
                            <%: Html.DisplayFor(m => itm.Fax)%>
                        </td>
                        <td>
                            <%: Html.DisplayFor(m => itm.Mobile)%>
                        </td>
                        <td>
                            <%: Html.ActionLink("Delete","Delete",new {id= itm.ContactId}) %>
                        </td>
                    </tr>
                    <% } %>
                </table>
            </fieldset>

            <div class="demo">
                <button >
                    <span class="ui-button-text">Save</span></button>
            </div>

            <% } %>
4

1 に答える 1

0

1 つのオプションは、javascript オブジェクト ( http://docs.jquery.com/Types ) を作成することです。保存ボタンを押すと、アイテムごとに jquery アイテムを使用して送信する必要がありますjQuery.each

それが役に立てば幸い

于 2012-04-18T14:57:18.443 に答える