2012-04-18 42 views
0

我有一個聯繫人信息,並希望用戶添加一些聯繫人,然後保存them.It意味着每個聯繫人我不想發送聯繫人信息到服務器,我想將它們保存在客戶端,然後在保存按鈕上點擊保存按鈕,然後將所有這些保存起來。我該怎麼做?如何添加到列表然後保存它們? 我的模型類是:Asp.net Mvc - 添加到列表並保存一次

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> 

      <% } %> 

回答

0

一種選擇是創建JavaScript對象(http://docs.jquery.com/Types),然後當保存按鈕被按下,你將不得不使用jQuery項目發送每件商品使用jQuery.each

希望它有幫助

相關問題