Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 247515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:15:56+00:00 2026-05-11T21:15:56+00:00

I am in doubt how to construct my views and viewmodels… Lets see a

  • 0

I am in doubt how to construct my views and viewmodels… Lets see a (simplified) situation. I have a registration view with two variations: openid and strandard username/password. I see two ways how to

implement this:

1.) First way: one view model and one view (some kind of Pseudocode):

class RegisterViewModel:
- public string OpenId {get;set;}  // used only in openid registration
- public string Username {get;set;}  // used only in username/password registration
- public string Password {get;set;}  // used only in username/password registration
- public string PasswordConfirmation {get;set;}  // used only in username/password registration
- public string Email {get;set;} // used in both registrations
- public string FirstName {get;set;}  // used in both registrations
- public string LastName {get;set;}  // used in both registrations
- public RegistrationType Type {get;set;}  // used in both registrations
...

RegisterView.aspx (System.Web.Mvc.ViewPage):

...
  <h1>Account info</h1>
  <% if (Model.Type  == Registration.Type.OpenId) { %>
     <%= Html.TextBox("OpenId") %>
  <% } else { %>
     <%= Html.TextBox("Username") %>
     <%= Html.TextBox("Password") %>
     <%= Html.TextBox("PasswordConfirmation") %>
   <% } %>
  <%= Html.TextBox("Email") %>

  <h1>Personal info</h1>
  <%= Html.TextBox("FirstName") %>
  <%= Html.TextBox("LastName") %>
..

2.) Second way: several view models and several views (user controls):

abstract class RegisterViewModel:
- public string Email {get;set;}
- public string FirstName {get;set;}
- public string LastName {get;set;}

class OpenIdRegisterViewModel:
- public string OpenId {get;set;}

class UsernameRegisterViewModel:
- public string Username {get;set;}
- public string Password {get;set;}
- public string PasswordConfirmation {get;set;}

UserControl.ascx:

...
  <h1>Personal info</h1>
  <%= Html.TextBox("FirstName")
  <%= Html.TextBox("LastName")
...

OpenIdRegisterView.aspx (System.Web.Mvc.ViewPage):

...
  <h1>Account info</h1>
  <%= Html.TextBox("OpenId") %>
  <%= Html.TextBox("Email") %>

  <% Html.RenderPartial("UserControl") %>
..

UsernameRegisterView.aspx (System.Web.Mvc.ViewPage):

...
  <h1>Account info</h1>
  <%= Html.TextBox("Username") %>
  <%= Html.TextBox("Password") %>
  <%= Html.TextBox("PasswordConfirmation") %>
  <%= Html.TextBox("Email") %>

  <% Html.RenderPartial("UserControl") %>
...

I think that the first way is not so OO, but it is easiery to align the view, and the second way is more oo, but it is hard to align elements – that is the reason why I didn’t put email into the user control, because I want to have email near account info.

What option would you choose and why? Maybe some 3rd option? Where is the limit between these two options (when you choose first, when second)…

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:15:57+00:00Added an answer on May 11, 2026 at 9:15 pm

    I use the second option:

    • I can us the ascx on other views
    • If I
      use Ajax I can have one ascx loaded
      asynchronously if javascript is
      enabled or load the full page if not.
      That makes it easier to implement
      both: an Ajax and non-Ajax version

    I would only pass the required Model into ascx:

    I am not shure if I would realy put the common fields on the main view. It would be better to just be able to put the ascx on some other view and have all the fields you need.

    Most of us come from WebForm – world where ascx are very powerfull. It was the first thing I looked at when evaluating MVC. Well there was not much to see.

    But even in this very limited form they are usefull.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No doubt I'm missing something really simple here but I just can't see the
One doubt in MSSQL. There are two tables in a databases. Table 1 named
I have a doubt: - Is there any standard/convention that when should I use
LINQ simplifies database programming no doubt, but does it have a downside? Inline SQL
I am programming in C++ for many years, still I have doubt about one
I doubt it can be done portably, but are there any solutions out there?
No doubt, it's essential for understanding code to give member variables a prefix so
I doubt I am the only one who has come up with this solution,
So no doubt that building a domain model is something that I think happens
I am having a doubt in page_init, page preinit, load. I need to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.