I've been away from Fubu for a while now and I'm struggling with a simple concept, so I'm chalking it up to brain drain or something today.
Suppose I have a GET request that returns a view model with some summary information to display to the user. On the same view, I'd like to present a form for the user to fill out that will POST to another action. I can't for the life of me remember/figure out how to setup the view to do what I want. Here's my starting point:
My endpoint:
public class SomeEndpoint {
public SomeViewModel Get(SomeRequestModel request) {
// Get the summary information to display with the form.
SomeViewModel model = GetSummary();
return model;
}
public AjaxContinuation Post(SomeInputModel input) {
// Process the input and indicate success/failure.
return AjaxContinuation.Successful();
}
public class SomeRequestModel {}
public class SomeViewModel {
public Money OrderTotal { get; set; }
}
public class SomeInputModel {
public string Name { get; set; }
public int HowMany { get; set; }
...
}
}
My view:
<viewdata model="Full.Namespace.To.SomeViewModel" />
<h2>Summary</h2>
<p>Order Total: <Display property="OrderTotal" /></p>
!{ this.FormFor[[Full.Namespace.To.SomeInputModel]]() }
!{ this.Edit(???, m => m.Name) }
!{ this.Edit(???, m => m.HowMany) }
!{ this.EndForm }
I know that there are DisplayFor and InputFor extension methods that accept another model than the view's model. I tried breaking the form up into a partial, but just could not figure out how to scope the Edit calls to the form's model. Do I need to setup a partial action that simply returns a blank SomeInputModel so my partial works the way I expect it? Can I do this type of composition with action-less views that work on a simple newed-up model?
This seems silly that I don't get it. Perhaps it's time to switch to a career in teaching. :-P
Thanks,
-Matt