I have a ViewModel that I want to autobind to another ViewModel on post.
Eg. if I have
public class ViewModelA{
public string Stuff {get;set;}
}
public class ViewModelB{
public string MyStuff {get;set;}
.
.
.
}
For display/rendering purposes, I want the partial to bind to ViewModelA, because it's a much simpler object and hence it'll hopefully be much more reusable since creating an interactive view is a costly proposition.
However, I need all the form information on the page on post. I suppose I could widen the controller action to take both ViewModelA and ViewModelB, and then do additional logic to assign ViewModelA property into ViewModelB, but is there a cleaner, more declarative way to do this?
I guess I'm wondering if I could tag ViewModelA, with some attribute like this:
[Bind(Prefix = "ViewModelB", Include = "MyStuff")]
I know I can do it at the action level, but can I inject this logic at the ViewModel level?
Also would be nice if Razor follows a more CQRS approach. eg.
Html.TextBoxFor(target => target.Property, model => model.Property2)
So that on render, the textbox is initialized with Property2 value, but on post, it's posted to target.Property.