2013-08-01 55 views
0

我正在使用ASP.NET MVC 3 Razor。我在控制器中有一個列表方法,所以想要將這個列表綁定到一個按鈕的單擊事件的表上。我將如何實現這一功能。 這裏是我的控制器方法:綁定一個表單擊按鈕事件

public ActionResult getItnList(string scanCode) 
     { 
      List<List<String>> getitnDetails_List = getitnDetails(date, name); 
      ViewBag.getitnDetails = getitnDetails_List; 
      return Json(new { getitnDetails_List = getitnDetails_List }, JsonRequestBehavior. AllowGet); 
     } 

這裏是我的視圖代碼:

@{ 
    List<List<String>> str = (List<List<String>>)ViewBag.getitnDetails; 
    } 
<table id="list" width="100%"> 
    <td><b>Harvest Date</b></td> 
    <td><b>Product</b></td> 
@for (int i = 0; i <= str.Count - 1; i++) 
    <td>@str[i][0].ToString()</td> 
    <td>@str[i][1].ToString()</td> 
</table> 

我將如何綁定這個表列出按鈕的單擊事件?

回答

0

我不完全確定你在問什麼。但是,如果你想獲得點擊按鈕的列表,你可以使用jQuery.getJSON(http://api.jquery.com/jQuery.getJSON/)來檢索列表數據,然後用javascript插入它。或者你可以在動作中渲染列表,並簡單地使用json .get並插入結果。

+0

我已經有數據控制器列表。我只想將此列表綁定到按鈕單擊事件的表上。 – user2450398

0

試試這個

查看

<table> 
     <tr> 
      <th> 
       Name 
      </th> 
      <th> 
       PhoneNo 
      </th> 
      <th> 
       Address 
      </th> 
      <th> 
       Action 
      </th> 
     </tr> 
     @{var list = ViewBag.RegisterItems; } 
     @if (list != null) 
     { 
      foreach (var m in list) 
      { 
      <tr> 
      <td> 
         <input id="[email protected]()" type="text" class="hide" value="@m.Name.ToString()"/> 
       </td> 
       <td> 
         <input id="[email protected]()" type="text" class="hide" value="@m.PhoneNo.ToString()"/> 
       </td> 
       <td> 
         <input id="[email protected]ng()" type="text" class="hide" value="@m.Address.ToString()"/> 
        </td> 

      </tr> 

      } 
     } 
    </table> 

控制器

public ActionResult CustomerInfo() 
    { 
     ViewBag.RegisterItems = GetAllRegisterData(); 
     return View(); 
    }