【发布时间】:2011-03-03 20:54:49
【问题描述】:
我有一个强类型视图,模型中有一个自定义对象列表。
在视图中,我为列表中的每个对象显示文本框:
@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();
}
form["m.Text"] = "testnewdata1,testnewdata"
但是我如何将它映射到模型,所以我有每个对象的更新值。 或者我怎样才能从formcollection中干净地得到它,像这样.. form[someid]["m.Text"]
编辑:
我也尝试过将模型作为参数传递,但模型数据为空。
[HttpPost]
public virtual ActionResult SaveData(LocalizationModel model, FormCollection form)
{
// Get movie to update
return View();
}
当我查看模型时:model.GlobalTexts = null
【问题讨论】:
标签: c# asp.net asp.net-mvc-3