我有这些 DTO
public class Header
{
public int HeaderId{get;set;}
public int Description{get;set;}
public List<HeaderItem> HeaderItems{get;set;}
}
public class HeaderItem
{
public int HeaderItemId{get;set;}
public string DetailDescription{ get; set; }
public bool Selected{ get; set; }
}
我有这个控制器
[HttpPost]
public ActionResult PostMethod(Header dto)
{
...
}
和这个 html
@using (Html.BeginForm("PostMethod", "Controller", FormMethod.Post, new { id = "form" }))
{
@Html.TextBoxFor(x => x.Description)
var grid = new WebGrid(Model.HeaderItems);
}
@grid.GetHtml(tableStyle: "grid",
htmlAttributes: new { id = "grid" },
columns: grid.Columns(
grid.Column("Selected", "Seç", format: (item) => Html.CheckBox(String.Format("Selected_{0}", (int)item.HeaderItemId), false)),
grid.Column("HeaderItemId", "", format: (item) => Html.Hidden("HeaderItemId")),
grid.Column("DetailDescription", "Description")
)
}
因此,此网格有一个复选框和一个 HiddenField,其中包含每行的 HeaderItemId 值。
我想发布我的表单并填充 Header 类的属性 HeaderItems。
我怎样才能达到这个解决方案?