Reputation: 11
one thing that has been puzzling me since learning MVC2 is the following case scenario:
I have a view which contains two latest news lists, a login form and a signup form.
Every example I found on Views and View Models so far has a one-to-one example such as a simple login form etc. But how do I create a model that provides the properties and validation for a login and signup form and manages the data for the news lists.
Can I pass multiple models in the strongly typed view?
When I created one model the form validation would fail as it expects all fields - login and signup to be filled.
I am missing some advanced examples or information. Any help is appreciated.
Upvotes: 1
Views: 1090
Reputation: 1390
I usualy create .ascx in this case.
I make ascx strongly typed for the model (in your case LoginModel) I make a second ascx strongly typed (in your case SignupModel).
Then I make aspx and put those 2 ascx-es inside of it <% Html.RenderPartial("Login", Model.Login); %> and similar for the other one.
And you make aspx also stronly typed as
class PageModel
{
public LoginModel Login { get; set; }
public SignupModel Signup { get; set; }
}
Upvotes: 2