2015-01-21 102 views
2

置HTML表我創建基於腳手架通過模型在MVC視圖中創建到控制器

@model IEnumerable<FleetLink.Domain.Entities.UserTable> 
@using (Html.BeginForm("Index", "Home", FormMethod.Post)) 
{ 
<table> 
@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.Master_IP) 
      @Html.TextBoxFor(modelItem=>item.Master_IP) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Master_Name) 
     </td> 
</tr> 
<tr><td><input type="submit" value="Submit" /></td></tr> 
</table> 
} 

在我的控制器我有一個獲取和指數

[HttpPost] 
public ActionResult Index(List<UserTable> list) 
    { 
     return View(); 
    } 
    [HttpGet] 
    public ActionResult Index() 
    { 
     var users= from userTable in _repo.GetUsers() 
        select userTable; 
     return View(users); 
    } 

POST方法列表我期待它會在點擊提交時調用post方法,並將整個表數據傳遞給Index HTTPPost方法。但它總是調用Index的get方法。目標是在用戶編輯後傳遞整個表格數據,以便我可以一次保存所有表格數據。請諮詢我做錯了什麼。

回答

1

我通過將foreach更改爲for(int i = 0 ....)以及將@using(Html.BeginForm(「Index」,「Home」,FormMethod.Post))更改爲 @using(Html.BeginForm(FormMethod.Post))

謝謝

相關問題