tags:

views:

50

answers:

1

Greetings!

I need assistance with ASP.NET MVC and the values posted from a form operation (form is inside a Partial View).

On my page to create a User Account, various form fields collect the information. The Partial View is backed by a ViewModel (UserAccountViewModel).

To validate and/or save the information, I need to pass the values of the form to UserAccountService. Back in Java and Struts 1.x, I used the getMap() method of the DynaActionForm, but being an ASP.NET newbie, I'm not sure of the best way to proceed.

On a post operation, are the fields of the ViewModel automatically updated? If that's the case, I could pass the ViewModel to the Service layer (not my preferred solution, but good enough).

Jason

+1  A: 

You can use the UpdateForm method in .net to have it automatically map the form data to your model based on similar naming.

UserAccountViewModel.UpdateForm(Request.Form);

UpdateForm will work on pretty much any class with properties, you just need to import the namespace. Here is a pretty good tutorial on form handling in asp.net mvc that uses this method. This sounds like it's a similar method to what you're used to in Java.

Parrots