1

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.

1 Answer 1

2

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; }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.