-1
我在用戶在運行時添加一些數據的視圖上有一個HTML表。我想通過控制器將該表的所有行保存在數據庫中.just像winform每個循環用於保存所有行的應用程序。如何在mvc4的視圖中存儲html表中的數據
我在用戶在運行時添加一些數據的視圖上有一個HTML表。我想通過控制器將該表的所有行保存在數據庫中.just像winform每個循環用於保存所有行的應用程序。如何在mvc4的視圖中存儲html表中的數據
爲您的表創建一個視圖模型:
public class YourTable
{
public IEnumerable<YourRow> Rows { get; set; }
}
創建強類型視圖。
@model SomePath.YourTable
// Your table editable content
// form with submit value that will post viewmodel to controller action
並在控制器動作,您應該處理後:
[HttpPost]
public ActionResult SaveTable(YourTable yourTable)
{
// save your table to the database
}
看一看這個職位上模型綁定列表 - http://haacked.com/archive/2008/10/23 /model-binding-to-a-list.aspx – David