【发布时间】:2010-09-24 11:41:57
【问题描述】:
在初始 cmets 后更新
模型中有一个名为“Account”的对象,其中有一个 int 属性 (Account.AccountID)
ViewB 有一个收集一些额外信息的表单 - 但也有一个填充有 Model.Account.AccountID 的文本框。
但是,当我提交 ViewB 时,Model.Account 变为空。
在我解释问题之前,显示一个简化版本可能更容易:
[HttpGet]
public ActionResult ViewA()
{
return View(new BlahModel());
}
[HttpPost]
public ActionResult ViewA(BlahModel model)
{
if(there_was_a_problem)
return View("ViewA", model);
else
return View("ViewB", model);
}
// have tried both httppost, httpget and no attribute here
public ActionResult ViewB(BlahModel model)
{
return View(model);
}
我通过 GET 加载 ViewA,填写强类型表单并提交 - 然后以下 View(再次 ViewA 或 ViewB,如果请求没有问题)就可以了……它可以完全访问整个模型并可以显示其中的属性。
问题是,如果我随后在 ViewB 中提交一个表单(该表单发布到 ActionResult ViewB) - 模型突然在整个过程中都有空属性,即使它使用相同的模型 - 并且在发布之前已经拾取了所有值成功。
有什么想法吗?
非常感谢
【问题讨论】:
-
ViewB 上有哪些您希望填充模型的 html 对象?在调试中运行并查看 response.form 对象