I have example code in which the signature of the Create action menthod in the con开发者_JAVA百科troller looks like this:
[HttpPost]
public ActionResult Create(JobCardViewData viewData)
I have just created a new MVC application and the same signature looks like this:
[HttpPost]
public ActionResult Create(FormCollection collection)
I would prefer to know how to implement my action methods like the top example, or at least how to convert from the FormCollection to a business object without going as low level as using Reflection.
Personally I avoid using FormCollection
as it is a collection of magic strings. I would recommend you to always use this signature:
[HttpPost]
public ActionResult Create(JobCardViewData viewData)
and leave the model binder do the job of parsing the request parameters into a strongly typed object (you don't need to resort to reflection or doing anything).
精彩评论