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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 157k
  • Answers 157k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Something along these lines: insert into popular_tags (id, `count`) select… May 12, 2026 at 11:01 am
  • Editorial Team
    Editorial Team added an answer Considering that Integration with .NET Remoting links back to it… May 12, 2026 at 11:01 am
  • Editorial Team
    Editorial Team added an answer In general, d<motion> will delete from current position to ending… May 12, 2026 at 11:01 am

Related Questions

I am in doubt how to construct my views and viewmodels... Lets see a
i just tinkered around with Google Guice for Dependency Injection and started integrating it
While reading the answers to this question I got a doubt regarding the default
Hey guys, I want to store a categorized list of URLs. This is an
I am relatively new to Xcode and one thing that has bothered me is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.