How to read a complex view model on POST?

Posted by Interfector on Stack Overflow See other posts from Stack Overflow or by Interfector
Published on 2010-06-05T20:33:55Z Indexed on 2010/06/05 20:42 UTC
Read the original article Hit count: 167

Filed under:
|

Hello, I have an user view model that has the following properties:

 public User user;
    public List<Language> Languages;

I send the above model to the view and use html helpers to build the form, so I end up with something like:

<form action="/Users/Edit/5" method="post"><input id="user_UserId" name="user.UserId" type="hidden" value="5" />
First Name
Last Name
Email
Language
- en en

Now, I try to read the POST in something that initially was something like :

[AcceptVerbs( HttpVerbs.Post )]

public ActionResult Edit( int UserId, FormCollection form ) {

and cannot get the user.UserId variable, user.FirstName variable etc.

Any idea what needs to be done to be able to read this kind of POST request. I'm kind of reluctant to modifying my ViewModel as it is very simple and easy to maintain as it is.

Thank you.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about postback