TAGS :Viewed: 16 - Published at: a few seconds ago

[ MVVM and ModelBinders in the ASP.NET MVC Framework ]

I've got a series of views, each are typed to have their own ViewModel class which contains everything they need to display themselves, for example:

public class CreateResourceViewModel
     public Project Parent { get; set; }
     public SelectList Categories { get; set; }
     public Resource Resource { get; set; }

The post action method for this I'd like to use would look like this:

[AcceptVerbs (HttpVerbs.Post)]
public ActionResult Create (Resource resource)
   // Update code...

Notice that the only object I'm interested in is the Resource property of the CreateResourceViewModel, not the CreateResourceViewModel itself. Everything else is just gravy for for the user, what they're updating is the resource class...

Is this possible within the MVC Framework (even if it's v2 CTP)?

Thanks all

Answer 1

Sure. Use:

 public ActionResult Create([Bind(Prefix="Resource")]Resource resource)