UpdateModel 方法如何将 FormCollection 值填充到我们的实例中?

发布于 2024-09-08 17:50:26 字数 425 浏览 1 评论 0原文

在此示例中,UpdateModel 方法如何用 formValues 填充 person 实例? 我认为 UpdateModel 在通过 formValues 填充 person 时使用反射,但是 updatemodel 如何捕获 formValues 参数?

[HttpPost]
public ActionResult Edit(int ID,FormCollection formValues)
{
     Person person= db.PersonSet.Single(p => p.PersonID == ID);
     UpdateModel(person);
     db.SaveChanges();
     return RedirectToAction("Details", new { ID = person.PersonID });

}

In this example how UpdateModel method fill person instance with formValues?
I think UpdateModel use reflection while filling person by formValues but how updatemodel catch formValues parameter ?

[HttpPost]
public ActionResult Edit(int ID,FormCollection formValues)
{
     Person person= db.PersonSet.Single(p => p.PersonID == ID);
     UpdateModel(person);
     db.SaveChanges();
     return RedirectToAction("Details", new { ID = person.PersonID });

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花间憩 2024-09-15 17:50:26

我不认为它确实如此,从当前上下文中获取表单集合要容易得多。

如果 UpdateModel 方法要将参数发送到调用它的方法,则它必须获取堆栈转储并深入查找参数。此外,这并不是获取数据的明显方法。

I don't think that it does, it's a lot easier to just get the form collection from the current context.

If the UpdateModel method would get the parameter sent to the method calling it, it would have to get a stack dump and dig around to find the parameters. Besides, that would not be an obvious way of getting the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文