开发者

How UpdateModel method fill FormCollection values to our instance?

开发者 https://www.devze.com 2023-01-05 20:28 出处:网络
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 ?

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 });

}


I thinks it uses something like this:

var fc = new FormCollection(Controller.Request.Form);

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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消