2012-04-10 8 views
1

私はテーブルを持っている:ボタンの後ポスト値

<table id="selectedInv"> 
     <thead> 
      <tr class="alternate"> 
       <th> 
        Barcode 
       </th> 
       <th> 
        OverAll Count 
       </th> 
       <th> 
        Transfer Count 
       </th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr class="1"> 
       <td> 2323 </td><td> 9 </td><td><input type="text" value="3"></td></tr> 
      <tr class="2"> 
       <td> 2329 </td><td> 5 </td><td><input type="text" value="2"></td></tr> 
      <tr class="3"> 
       <td> 2329 </td><td> 3 </td><td><input type="text" value="1"></td></tr> 
     </tbody> 
    </table> 

クリック私は

などのデータを収集したい[{1,3}、{2,2 }、{3,1}]

[{A、B}は、a行の=クラス名、B =この行にテキスト値を入力します。

このデータを行動方法に投稿するには、これを行うにはどのような方法が良いですか?

+0

のために良いことを証明私たちにあなたがしようとした道を示す... – gdoron

+0

だろう、私は、収集するデータのテーブルを反復することができます。どのようにasp.net mvcのアクションメソッドにこのデータを渡す方法? – loviji

答えて

2

私は、各行からデータを収集するための2つのフィールド、すなわちクラスと転送回数を持っていると思う。私は、私の見解では、私は、HTML

<table id="selectedInv"> 
     <thead> 
      <tr class="alternate"> 
       <th> 
        Barkod 
       </th> 
       <th> 
        OverAll Count 
       </th> 
       <th> 
        Transfer Count 
       </th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr class="1"> 
       <td> 2323 </td><td> 9 </td><td><input name="data[0].TransferCount" type="text" value="3"><input type="hidden" value = "1" name = "data[0].CodeClass"/></td></tr> 
      <tr class="2"> 
       <td> 2329 </td><td> 5 </td><td><input type="text" value="2" name="data[1].TransferCount"><input type="hidden" value = "1" name = "data[1].CodeClass"/></td></tr> 
      <tr class="3"> 
       <td> 2329 </td><td> 3 </td><td><input type="text" value="1" name="data[2].TransferCount"><input type="hidden" value = "1" name = "data[2].CodeClass"/></td></tr> 
     </tbody> 
    </table> 

あなたは、インデックスメソッドにフォームを掲示していると仮定し、次の作成するループを記述し

public class ViewModel 
{ 
    public int CodeClass{get;set;} //class is reserved word 
    public int TransferCount{get;set;} 
} 

のようにそれのためのビューモデルになるだろう。それはのようになります

public ActionResult index(IEnumerable<ViewModel> data) 
{ 
//do something with data 
} 

フォームを投稿する送信ボタンを忘れないでください。詳細についてはsearchthis article
を読んでも、私が知っている、最良の方法は何尋ねる前

+0

興味深い解決策、私は試してみます – loviji

+0

名前属性はmvcモデルバインディングで重要です –