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
MVVM stands for Model-View-View Model. This pattern supports two-way data binding between view and View model. This enables automatic propagation of changes, within the state of view model to the View. Typically, the view model uses the observer pattern to notify changes in the view model to model.
The MVC pattern is most popular and is used for ASP.NET, iOS, and Android development. The MVP pattern is mostly used for ASP.NET Web Forms applications, and MVVM is used for WPF and Silverlight development.
A model is usually more closely related to how your data is stored (database, services, etc.) and the model will closely resemble those. The ViewModel on the other hand is closely related to how your data is presented to the user. It is usually a flatten version of your model, denormalized, etc.
The key to MVVM in MVC is moving logic out of the MVC controller and into a view model class that contains properties that you can bind to the user interface. The controller should only call a method in your view model, and periodically set a property or two prior to calling that method.
Sure. Use:
public ActionResult Create([Bind(Prefix="Resource")]Resource resource)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With