开发者

Strongly typed Update and Create controller actions

开发者 https://www.devze.com 2023-01-06 13:52 出处:网络
I have example code in which the signature of the Create action menthod in the con开发者_JAVA百科troller looks like this:

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

0

精彩评论

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