asp.net mvc strongly typed helpers - should your render binding object be the same as your posting object?

前端 未结 7 1438
刺人心
刺人心 2021-01-02 22:52

i see that asp.net mvc 2 has strongly typed helped and looking initially at the way it works i think maybe i am doing something wrong in asp.net mvc 1 in terms of data bindi

7条回答
  •  情书的邮戳
    2021-01-02 23:28

    Just looking at your specific situation, the following points occur to me.

    1) The two models are very similar indeed 2) If you add "MiddleName", you have to add it in two places 3) When you say "I only want to pass back a slim object" - the actual POST will contain the same amount of data, whether you bind to the original model or a new one (it will contain a key, value pair for each user-input within the form) 4) You preclude the option of displaying the data on your "saved ok" or "something isn't valid" page as it isn't part of the model

    For these reasons, I would recommend using the same model for the GET and POST of the action.

提交回复
热议问题