我有一個強類型的視圖,模型中有一個自定義對象列表。MVC3,從列表中獲取更新的表單數據
在視圖中顯示我的文本框列表中的每個對象:
@using (Html.BeginForm("SaveData", "Localization", FormMethod.Post))
{
foreach (YB.LocalizationGlobalText m in Model.GlobalTexts)
{
@Html.Label(m.LocalizationGlobal.Name)
@Html.TextBoxFor(model => m.Text)
<br />
}
<input type="submit" value="Save" />
}
現在我怎麼才能從文本框更新的數據在我的模型。 我可以在看的FormCollection更新的數據有:
[HttpPost]
public virtual ActionResult SaveData(FormCollection form)
{
// Get movie to update
return View();
}
形式[「m.Text」] =「testnewdata1,testnewdata」
但我怎麼得到這個映射到模型,所以我有每個對象的更新值。 或者我怎樣才能得到它乾淨地從的FormCollection,這樣的事情..形成[someid] [「m.Text」]
編輯:
我也試過路過模型作爲參數,但模型數據爲空。
[HttpPost]
public virtual ActionResult SaveData(LocalizationModel model, FormCollection form)
{
// Get movie to update
return View();
}
當我看着模型:model.GlobalTexts = NULL
我該如何獲得ID?我試圖保存每一個對象,而不僅僅是一個。 – redrobot 2011-03-03 21:08:16
我將通過編輯進行更新。鑽孔。我忘了你正在處理一個對象列表。 – Chev 2011-03-03 21:09:23
有你去,告訴我,如果這讓你在正確的軌道上。 – Chev 2011-03-03 21:20:19