2011-07-08 65 views
0

我的代碼是MVC Html.CheckBox列表和jQuery後

<% using (Html.BeginForm()) 
     {%> 
    <table> 
     <tr> 

      <th> 
       LabelID_FK 
      </th> 
      <th> 
       LabelName 
      </th> 
      <th> 
       LabelIsDocument 
      </th> 
     </tr> 
     <% foreach (var item in Model) 
      { %> 
     <tr> 

      <td> 
       <%: item.LabelID_FK %> 
      </td> 
      <td> 
       <%: item.LabelName %> 
      </td> 
      <td> 
       <%-- <input type="checkbox" value="df" id="chk" onclick="check()" />--%> 
       <%=Html.CheckBox("chk_"+ item.LabelID_FK)%> 
      </td> 
     </tr> 
     <% } %> 
    </table> 
    <p> 
     <input type="button" value="submit" id="btn" /> 
    </p> 

它們顯示了文件標籤,讓用戶可以選擇它複選框列表。 我想通過數據列表哪個用戶選擇複選框它使用jquery post 我該怎麼辦?

回答

0

我用這個代碼,當用戶點擊按鈕,工作非常好

[HttpPost] 
     public ActionResult DocumentLabel(FormCollection model) 
     { 


      for (int i = 0; i < model.Count; i++) 
      { 
       AriaCRMEntities aria = new AriaCRMEntities(); 
       DocumentLabel label = new DocumentLabel(); 
       string lbl = model[i].ToString(); 
       string[] check = lbl.Split(','); 

       bool chk = Convert.ToBoolean(check[0]); 

       string name = model.Keys[i].ToString(); 
       string[] n = name.Split('_'); 
       string lblid = n[1]; 

       if (chk) 
       { 
        label.LabelID_FK = Int32.Parse(lblid); 
        Guid id = Guid.NewGuid(); 
        label.DocumentID_FK = id; 

        aria.DocumentLabels.AddObject(label); 
        aria.SaveChanges(); 
       } 

      } 


      return Content("0ok"); 
     } 

,但我想的jQuery後,我需要陣列複選框白衣選擇它傳遞給控制器​​?