2014-03-14 34 views
0

我將我的列表綁定到如下圖所示的表格。當按下刪除按鈕時,我無法獲得控制器中的#ID。如果按下刪除按鈕,請指導某人如何獲取控制器中選定的#ID?如何通過單擊視圖上的刪除按鈕來獲取控制器中選定的行ID?

enter image description here

這裏是我的控制器代碼。

[HttpPost] 
    public ActionResult AddOrUpdateProducts(ProjectViewModel model = null, string Command = null) 
    { 
     if (Command == "Delete") 
     { 
     //Delete Item from list by #ID from 
     } 
     if (Command == "Submit") 
     { 
      //Save Items list 
     } 
     return View(model); 
    } 

回答

0

您可以在您的視圖

<input type="hidden" id="forid" name=""forid"/> 

考慮,使用隱藏域,據我所看到的每一個元素在裏面td.You可以使用jQuery單擊功能改變像隱藏字段的值下面

$('.delete').click(function(){ 

    var id=$(this).parents('tr').children(':first').text();// I am supposing that id is placed in first td of row then set this value to hidden field 
    $('#forid') .val(id); 

}) 

然後在控制器,你可以得到使用Request["forid"]

這個值
相關問題