UpdateModel 方法如何将 FormCollection 值填充到我们的实例中?
在此示例中,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为它使用这样的东西:
http:// msdn.microsoft.com/en-us/library/system.web.httprequestbase.form.aspx
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller_members.aspx
http://msdn.microsoft.com/en-us/library/dd492288.aspx
I thinks it uses something like this:
http://msdn.microsoft.com/en-us/library/system.web.httprequestbase.form.aspx
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller_members.aspx
http://msdn.microsoft.com/en-us/library/dd492288.aspx
我不认为它确实如此,从当前上下文中获取表单集合要容易得多。
如果 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.